我试图将一些相对简单的内容从Excel 2007复制粘贴到Word 2007中。我查看了这个网站和其他网站,但总是被同一个问题困扰 - 下面代码的第三行不停地报“未定义用户类型”错误信息。我很困惑,因为我只是从另一个解决方案中抄来的(并且在尝试抄取其他解决方案时也遇到类似的问题)。有人能告诉我是什么原因导致了这个错误,以及为什么会出现吗?
Sub ControlWord()
' **** The line below gives me the error ****
Dim appWD As Word.Application
' Create a new instance of Word & make it visible
Set appWD = CreateObject("Word.Application.12")
appWD.Visible = True
'Find the last row with data in the spreadsheet
FinalRow = Range("A9999").End(xlUp).Row
For i = 1 To FinalRow
' Copy the current row
Worksheets("Sheet1").Rows(i).Copy
' Tell Word to create a new document
appWD.Documents.Add
' Tell Word to paste the contents of the clipboard into the new document
appWD.Selection.Paste
' Save the new document with a sequential file name
appWD.ActiveDocument.SaveAs Filename:="File" & i
' Close this new word document
appWD.ActiveDocument.Close
Next i
' Close the Word application
appWD.Quit
End Sub