能有人帮 - 我使用这个代码复制从Excel到Word中的数据:从指定的复制数据的Excel文件word文档
Sub CreateRapport()
Dim wdApp As Object
Dim wd As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wd = wdApp.Documents.Add
wdApp.Visible = True
Sheets("Rapport").Activate
Set Rng = ThisWorkbook.ActiveSheet.Range("A1:E76")
Rng.Copy
With wd.Range
.Collapse Direction:=0 'Slutet av dokumentet
.InsertParagraphAfter 'Lägg till rad
.Collapse Direction:=0 'Slutet av dokumentet
.PasteSpecial False, False, True 'Pasta som Enhanced Metafile
End With
End Sub
什么会我需要在代码复制修改来自指定Excel文件的数据,例如“C:\ Book.xlsx”(不是ThisWorkbook)?我是VBA中的新手,所以任何提示都会有所帮助。 谢谢!
我想只指定存放excel文件的文件夹(不是特定的文件),所以数据可以直接从它们复制到Word中。谢谢。 – IvanS