忘记说了,要加入word的Object library才行的。
方法:
在excel的vb编辑器菜单中,选“工具”---“引用”---在那列表中往下找“Microsoft Word 9.0 Object Library”,把它前面的框勾上,确定。
这样执行就没错了。
Sub Macro1()
Dim appWD As Word.Application, doc As Object
Range("A1:C3").Select
Selection.Copy
Set appWD = CreateObject("Word.Application")
appWD.Visible = True
Set appWD = GetObject(, "Word.Application")
Set doc = GetObject("D:\doc1.doc")
appWD.Visible = True
With appWD.Selection.Find
.Text = "指定位置"
.Wrap = wdFindContinue
End With
appWD.Selection.Find.Execute
appWD.Selection.MoveRight Unit:=wdCharacter, Count:=1
appWD.Selection.TypeParagraph
appWD.Selection.MoveLeft Unit:=wdCharacter, Count:=1
appWD.Selection.PasteExcelTable False, False, False
appWD.Quit (wdSaveChanges)
End Sub
直接复制粘贴就行啊