要解决这个问题,我们可以按以下步骤操作:
Sub DataFromExcel() Dim xlApp As Object Dim xlWB As Object Dim xlSheet As Object Dim wdDoc As Document Set wdDoc = ActiveDocument Set xlApp = CreateObject("Excel.Application") Set xlWB = xlApp.Workbooks.Open("Path\To\Your\Excel\File.xlsx") Set xlSheet = xlWB.Sheets("Sheet1") wdDoc.Content.InsertAfter xlSheet.Range("A1").Value xlWB.Close xlApp.Quit Set xlSheet = Nothing Set xlWB = Nothing Set xlApp = Nothing End Sub
希望这个解决方法能够帮助你编写一个可以从各种Excel工作表中提取数据的带宏的Word报告。