在Excel中通过VBA,在Word文档的特定位置(书签位置)插入文本Sub GetWordVersionEarly()
' Early Binding ??? Dim WordApp As Object?? 'Word Application对象 ??? Dim WordDoc As Document 'Word Document对象 ??? ??? Dim shtExcel As Worksheet 'Excel Sheet对象 ??? Dim rngExcel As Range???? 'Exce Range对象 ??? Set shtExcel = Sheets("sheet1") ??? Set rngExcel = shtExcel.Range("A1") ??? ??? Set WordApp = CreateObject("Word.Application") '创建Word Application对象 ??? WordApp.Visible = True? '显示Word程序(Word对象创建后会自动隐藏) ??? ??? With WordApp '??????? Set WordDoc = .Documents.Open("c:\Today 1.dot") '打开Word模板文件 ??? Set WordDoc = .Documents.Add("C:\Today 1.dot")? '依照模板文件,新建Word文档。 语法 Documents.Add(Template, NewTemplate, DocumentType, Visible) ??? Call Excel2Word(WordDoc, "a", rngExcel.Value)??????? '将Word书签和待文本传入过程Excel2Word ??? End With ??? '??? WordApp.Save (True) '??? WordApp.Quit??????????? '关闭Word Application对象 '??? Set WordApp = Nothing?? '释放Word Application对象 End Sub |