我想将数据从 excel 复制到 word 表,然后从表中删除一些列。我可以将数据复制到表中,但是当我删除列时出现错误:
无法访问此集合中的各个列,因为表格具有混合单元格宽度。
我的代码:
Public Tbl1 As Table
Sub callExcel()
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook
Set exWb = objExcel.Workbooks.Open("C:\Users\ismayilov\Desktop\test")
roomNumber = InputBox("Enter the room number to copy word:", "Room Number")
ActiveDocument.FormFields("Text1").Result = roomNumber
exWb.Sheets("Sheet1").Range("$A:$H").AutoFilter Field:=8, Criteria1:=roomNumber
Dim rVis As Range, rData As Range
exWb.Sheets("Sheet1").Range("$A1:$H600").Copy
Set Tbl1 = ActiveDocument.Tables.Add _
(Range:=Selection.Range, numRows:=1, NumColumns:=8)
Tbl1.Range.Paste
Tbl1.Columns(1).Delete
exWb.Close SaveChanges:=True
Set exWb = Nothing
Set Tbl1 = Nothing
End Sub