Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Portland, Oregon
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Determining the active line number in a document (2000)

    I'm creating a pleading template for a law firm. Each template caption (which is a table) is a different size. After the caption is created, we're inserting some text from AutoText. I want the Autotext to be "dropped" into this document at line 20. Using VBA I am unable to determine which line my cursor is currently at. Doing a search in VBA for "line" doesn't reveal how to count the lines.
    Can anyone help? <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>
    Thanks
    Charlotte Quiroz

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

    Re: Determining the active line number in a document (2000)

    A primitive but effective way to get to line 20 is:

    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=19

  3. #3
    2 Star Lounger
    Join Date
    Mar 2004
    Location
    Portland, Oregon
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining the active line number in a document (2000)

    This would work if the document were already created. In my case, after the caption is created, I may be on line 16 and there're no lines of text after that... I want Word to determine where the cursor is, then add enough paragraph returns to add up to 20, THEN add the text from Autotext. Thanks

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

    Re: Determining the active line number in a document (2000)

    The Word gurus probably know of more elegant ways to do this, but this may help:

    Dim lngLineCount As Long
    Dim i As Long
    Selection.EndKey Unit:=wdStory
    lngLineCount = Selection.Information(wdFirstCharacterLineNumber)
    If lngLineCount < 20 Then
    For i = 1 To 20 - lngLineCount
    Selection.TypeParagraph
    Next i
    Else
    Selection.HomeKey Unit:=wdStory
    Selection.MoveDown Unit:=wdLine, Count:=19
    End If
    ' You should be on line 20 now.
    ActiveDocument.AttachedTemplate.AutoTextEntries("b lahblah").Insert _
    Where:=Selection.Range, RichText:=True

  5. #5
    New Lounger
    Join Date
    Dec 2003
    Location
    Seattle, Washington, USA
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Determining the active line number in a document (2000)

    Could you design each caption to have its last paragraph, or a paragraph immediately following it, defined in Format-Paragraph-Spacing-After to be the exact height that would allow the next inserted text to appear at line 20? Or define styles unique to each template, to be applied to the first line of the inserted autotext, which are similarly defined in Format-Paragraph-Spacing-Before?

Posting Permissions

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