以下是引用fntfgz在2019/6/3 22:30:00的发言:
老师,怎么把一个excel插入到word呢?我看您的哪个例子是把word插入到word
一样的,用vba打开excel,拷贝,然后粘贴过去,就行了的。如
Dim app As New MSWord.Application
try
Dim fileName = "d:\test.doc"
Dim doc = app.Documents.Open(fileName)
Dim App2 As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App2.WorkBooks.Open("D:\test.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) '指定要复制的工作表
Ws.UsedRange.Copy
wb.saved = True
app2.DisplayAlerts = False
app.ActiveWindow.Selection.WholeStory
app.Selection.MoveRight(Unit:=1)
app.Selection.TypeText(Text:=vbcrlf)
app.ActiveWindow.Selection.paste
App2.Quit
app.visible = True
catch ex As exception
msgbox(ex.message)
app.Quit
End try