从Excel中获取数据并插入到现有的Word表格中?

我知道这已经被问过,但是我只能find在你传输数据的时候在Word中创build表格的网站。

我有一个带有3个表格的Word文档,并希望从客户端发送到Word表格中的某些单元格的Excel文件中提取数据。 EG我想在Excel中把单元格D3的内容放在Word的第二个表格的单元格2,2中? 有没有办法引用哪个表来插入数据?

任何人都可以帮忙,或者只是把我推向正确的方向,因为我相对较新的macros等。当我们使用Word文档,并有Excel文件发送给我们,会使Word中的macros更有利吗?

谢谢

我已经设法解决这个问题,通常它是相对简单的,但是要感谢@David Zemens推动正确的方向。 我不知道以前通过“ThisDocument”进行search时,我是怎么错过了“Tables”的。

  Sub GetData() Dim objExcel As New Excel.Application Dim exWb As Excel.Workbook Dim ExcelFileName As String ExcelFileName = "{Put the directory of Excel file here}" Set exWb = objExcel.Workbooks.Open(ExcelFileName) 'Set the text of the cell from Excel to the cell in the specified table in Word (the second table in this instance) ActiveDocument.Tables(2).Cell(2, 2).Range.Text = exWb.Sheets("Test").Cells(2, 1) ' Close Excel bits exWb.Close Set exWb = Nothing End Sub