Consulting

Results 1 to 2 of 2

Thread: Import Table from Excel to Word

  1. #1

    Import Table from Excel to Word

    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.xls x")


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


    exWb.Close


    Set exWb = Nothing


    End Sub


    Private Sub ImportCost_Click()


    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    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
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •