【发布时间】:2014-10-09 14:22:37
【问题描述】:
我想将Excel中的一些单元格内容导出到Word,我想做这样的事情
Sub CreateNewWordDoc()
' to test this code, paste it into an Excel module
' add a reference to the Word-library
' create a new folder named C:\Foldername or edit the filnames in the code
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add
' or
'Set wrdDoc = wrdApp.Documents.Open("C:\Foldername\Filename.doc")
' sample word operations
With wrdDoc
For i = 1 To 100
.Content.InsertAfter "Here is a sample test line #" & i
.Content.InsertParagraphAfter
Next i
If Dir("C:\Foldername\MyNewWordDoc.doc") <> "" Then
Kill "C:\Foldername\MyNewWordDoc.doc"
End If
.SaveAs ("C:\Foldername\MyNewWordDoc.doc")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
End Sub
但是当测试函数 Excel 时说“编译错误:未定义用户定义的类型” 我想这是我缺少的库,但我在工具->参考(VBA)中找不到任何合适的, 比如 Microsoft Office World 或 Microsft Word...我在哪里可以找到它们?
【问题讨论】: