Results 1 to 2 of 2

Thread: creating separate tables in VBA word

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2019

    creating separate tables in VBA word

    So basically, I am trying to create two separate tables in VBA, one below the other.

    I've checked a lot of threads, but cant figure it out. keep getting error. I am able to create the first table, or create a second table nested in the first one, but is unable to create two separate tables.

    Dim objWord
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    Set oDoc = objWord.Documents.Add
    Set oTable = oDoc.Tables.Add(oDoc.Range(0, 0), 6, 4)

    Set aRange = ActiveDocument.Paragraphs.Last.Range

    Set oTable2 = oDoc.Tables.Add(oDoc.aRange, 5, 4)

    oTable.Borders.Enable = True
    oTable2.Borders.Enable = True

    the line "Set oTable2 = oDoc.Tables.Add(oDoc.aRange, 5, 4)" gets an error. This is where i try to create the second table, and I am not sure what to do about the aRange that was declared earlier, or if i am even in the right direction.

  2. #2
    Join Date
    Dec 2004

    Re: creating separate tables in VBA word

    just need some minor changes
    Set oTable = odoc.Tables.Add(odoc.Range(0, 0), 6, 4)
    Set arange = odoc.Paragraphs.Last.Range
    Set oTable2 = odoc.Tables.Add(arange, 5, 4)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed

Posting Permissions

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


Click Here to Expand Forum to Full Width