Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jan 2005
    Location
    Boston, Massachusetts, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to add a blank line before table on first line (2000/2002)

    Hello All,

    I have a template that has a word table inserted at the first line of the document which I have setup for users.

    I'd like to be able to programmatically add a line of text before the start of the table (for reasons to annoying to go in to here).

    I thought I'd be able to use the InsertBefore command, but this just inserts the text into the 1st cell of the table.


    Here's my code snippet
    <pre>Dim tTable as Table
    If ActiveDocument.Tables.Count > 0 Then

    For Each tTable In ActiveDocument.Tables
    If tTable.Range.Start = ActiveDocument.Range.Start Then
    tTable.Range.InsertBefore "HELLO" & vbCrLf
    'ActiveDocument.Sections(1).Range.Characters(1).In sertBefore "HELLO" & vbCrLf
    End If
    Next

    End If
    </pre>



    I've tried to insert before both the table and at the beginning of the Range my document, except both of these end up inserting the HELLO into the 1st cell of the table.

    Any ideas on how to insert something before a table on the first line. Putting the table on to the 2nd line is not an option, I do not have access to change the templates.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to add a blank line before table on first line (2000/2002)

    Try this:

    Selection.HomeKey Unit:=wdStory
    Selection.SplitTable

    or

    Selection.HomeKey Unit:=wdStory
    Selection.InsertBreak Type:=wdColumnBreak

    Credits: Adding a Line Before a Table.

  3. #3
    4 Star Lounger
    Join Date
    Oct 2001
    Location
    New York, New York, USA
    Posts
    538
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: How to add a blank line before table on first line (2000/2002)

    Hope I am not misunderstanding what you want, but would this most simple of macros be what you want?

    Sub Macro1()

    Selection.SplitTable
    End Sub

    Curious

  4. #4
    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: How to add a blank line before table on first

    This should work when the insertion point is in the first cell (or maybe it's the first row?). Selecting the entire table should more or less accomplish that, if necessary:

    Selection.Tables(1).Select
    ' Optional:
    ' Selection.Collapse wdCollapseStart
    Selection.SplitTable

    Or if the selection is not already in the table...

    ActiveDocument.Tables(1).Range.Cells(1).Select
    Selection.SplitTable

    In the help file for Word 2002, there is an even better sounding approach:

    ttable.Split BeforeRow:=1

    However, it gives an error when the row number is 1.

    This is all beginning to sound suspiciously familiar, as though we had another thread in which we banged our heads against this brick wall...

  5. #5
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to add a blank line before table on first

    I've got a simpler question. Quite apart from any macros--when I open a document, create a table, then decide I want to put in some text before the table, I can't access the space above the table to insert a hard return/paragraph mark and move the table down. Is there a knack that anyone knows?

    Philip

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to add a blank line before table on first

    Press Ctrl+Home to go to the beginning of the document.
    Press Enter to insert a paragraph before the table.

  7. #7
    3 Star Lounger
    Join Date
    Jun 2004
    Location
    Oxford, Oxfordshire, United Kingdom
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to add a blank line before table on first

    many thanks--I don't know what I did before I found this board

    Philip

  8. #8
    New Lounger
    Join Date
    Jan 2005
    Location
    Boston, Massachusetts, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to add a blank line before table on first

    Thank you, this worked great.

Posting Permissions

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