【问题标题】:Excel to Word: User-defined type not defined, missing Word library in referenceExcel 到 Word:未定义用户定义类型,参考中缺少 Word 库
【发布时间】: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...我在哪里可以找到它们?

【问题讨论】:

    标签: excel ms-word export vba


    【解决方案1】:

    引用取决于您使用的 MSOffice 版本。 对我来说,它是“Microsoft Word 12.0 对象库”

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2012-07-28
      • 1970-01-01
      • 2017-01-07
      • 2017-10-30
      • 2014-08-07
      • 2011-04-08
      • 2013-01-22
      • 2015-11-05
      • 1970-01-01
      相关资源
      最近更新 更多