Results 1 to 3 of 3
  1. #1
    anders
    Guest

    Creating multiple tables in Word ((VBA from VB6)) (English, VB, 6.0)

    I've created a VB6 app which gets data from a database and i'd like to generate a Word document.
    Everything is working fine until i get to the point where i wan't to create more than one table.

    When creating the first table i 'm setting the range Set MyRange = Selection.Range...
    Everything else i want written to the document after this table, i must use "oDoc.Range.InsertAfter "text_here". Otherwise the text will just end up in the table i just created!!

    So basically what i need to know is: How do i define specific ranges for specific tables (I don't know in advance how long/wide they will be as i'm creating them from a recordset)

    Is there another way than using ranges when creating forms??

    Any hints, help or references appreciated.

    Thanks
    Anders, Sweden

  2. #2
    Lounger
    Join Date
    Jan 2001
    Location
    Kingwood, Texas, USA
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating multiple tables in Word ((VBA from VB6)) (English, VB, 6.0)

    I don

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Creating multiple tables in Word ((VBA from VB6)) (English, VB, 6.0)

    (1) There is a tables collection:

    For i = 1 To ActiveDocument.Tables.Count
    ActiveDocument.Tables(i).Select
    Next

    You can address the entire table or individual cells, etc., as ranges:

    Dim myRange As Range
    Set myRange = ActiveDocument.Tables(i).Range

    (2) You can collapse a range to its endpoint to avoid overwriting the present contents. Ranges are faster than selections, although if you want the user to see what is going on, you might as well use the Selection object.

    myRange.Collapse Direction:=wdCollapseEnd

    You then can continue to "InsertAfter" as appropriate. Hope this helps.

Posting Permissions

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