PDA

View Full Version : [SOLVED:] Import Table from Excel to Word



kevinmpeters
03-11-2020, 06:27 AM
Hi All,
I'm trying to import a table from Excel directly into word. I can't find a way to pull the table itself in, and I'd prefer not to use a range as the table will be a varying number of rows depending on the source file. I also want to use specific Cells in the table to create headings earlier in the file, but the number of cells will be dynamic. Current code works fine to import a single cell, but can't figure out the exWB for a table. Any suggestions? Thanks much

Private Sub CommandButton1_Click()
Dim objExcel As New Excel.Application
Dim exWb As Excel.Workbook


Set exWb = objExcel.Workbooks.Open("C:\Users\Me\Desktop\SOWTest\CostingsCalculator.xlsx")


ThisDocument.ImportFromCostCalc.Caption = exWb.Sheets("Customer Facing (Std)").Range("B2")


exWb.Close


Set exWb = Nothing


End Sub


Private Sub ImportCost_Click()


End Sub

macropod
03-11-2020, 02:12 PM
Try something along the lines of:

Dim fRow As Long, lRow As Long, fCol As Long, lCol As Long
fRow = 2: fCol = 2: lRow = 10: lCol = 8
With exWb.Sheets("Customer Facing (Std)")
ThisDocument.ImportFromCostCalc.Caption = .Range(.Cells(fRow, fCol), .Cells(lRow, lCol))
End With