Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Insert Text Under Inserted Table in Word 1

Status
Not open for further replies.

UncleCake

Technical User
Feb 4, 2002
355
0
0
US
Hi, I am trying to write my first application in VB6 that will create a Word file that has lots of text and a few tables. The overall goal is to create a quote in Word populated with data from our database.

My first goal is to write text followed by a table and then followed by more text using just VBA in Word and running the macro to test it. After that I can work it into a VB6 application.

I have recorded a macro inserting a table as follows:

Code:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 8/9/2006 by
'
    ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:= _
        5, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
        wdAutoFitFixed
    With Selection.Tables(1)
        If .Style <> "Table Grid" Then
            .Style = "Table Grid"
        End If
        .ApplyStyleHeadingRows = True
        .ApplyStyleLastRow = True
        .ApplyStyleFirstColumn = True
        .ApplyStyleLastColumn = True
    End With
End Sub

My problem is that I don't know how to add additional text under the table. I can align and populate the table, but how do I get "out" of the table?

-Uncle Cake
 
There are a couple of ways to go. It depends on what else is happening in your document. And if you are going to using this with a table of more than one row.

As it stand, because the table is inserted at the Selection point, AND it has only one row
Code:
Selection.MoveDown Unit:=wdLine, Count:=1
You could have easily seen this when you recorded the macro. You should have actually moved the Selection out of the table yourself, and seen the code.

An alternative - if the inserted table is the current end of the document. It will have a paragraph mark after it, so
Code:
Selection.HomeKey Unit:=wdStory
moves the Selection to the end of the document, which in this case is outside the table.

There are other possibilities.

Gerry
My paintings and sculpture
 
Gerry,

I just wasn't trying to correct key movement, but after I went down I see the first example that you gave me. I think that I tried everything else including many key combinations with Enter, Shift, Ctl... Anyway, thanks for the tip, it works for me.

-Uncle Cake
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top