Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Nov 2003
    Location
    Bloomington, Minnesota, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add Asterisk to selected lines (Word 2003 SP3)

    We have a requirement to add an asterisk to selected lines (not paragraphs) of Word documents of around 100 pages. I created a macro that worked if applying to only one line, but if I selected more than one line, it rolled to the paragraph level.

    My latest idea is to create a table for each page, consisting of two columns, one row. The narrow left column is for the asterisk, and the larger right column is for text. We will have to adjust spacing in the left column to match the text. I'm not especially happy with this solution--especially for reports from another tool. Does anyone out there have a better idea? Thanks!

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

    Re: Add Asterisk to selected lines (Word 2003 SP3)

    A belated welcome to Woody's Lounge!

    Using a table is a good idea. The problem with adding asterisks to the lines themselves is that a line - unlike a paragraph - is not a natural unit in Word. Any change in the text or formatting - such as adding an asterisk! - may change the way lines break.

  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: Add Asterisk to selected lines (Word 2003 SP3)

    Does the text need to be editable? If not, this will place an asterisk and a space at the beginning of each line of a paragraph:

    <code>Sub AsteriskThis()
    Dim par As Word.Range
    With Selection
    ' Capture range of current paragraph
    Set par = .Paragraphs(1).Range
    ' Begin at the beginning
    .Collapse wdCollapseStart
    If .Start <> par.Start Then .MoveUp wdParagraph, 1
    ' Insert asterisks
    Do
    .TypeText "* " 'Beginning of line
    .EndKey wdLine
    If .End >= par.End - 2 Then Exit Do
    .TypeText Chr(11) 'End of line manual break
    Loop
    End With
    ' Clean up objects
    Set par = Nothing
    End Sub</code>

  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: Add Asterisk to selected lines (Word 2003 SP3)

    Oops, you just want selected lines. How about this one:

    <code>Sub AsteriskSelectedLines()
    Dim rngS As Word.Range
    With Selection
    ' Create a range to capture the selection
    Set rngS = Selection.Range
    ' Begin at the beginning
    .Collapse wdCollapseStart
    Do
    .HomeKey wdLine
    .TypeText Chr(11) & "* "
    .MoveDown wdLine
    If .End >= rngS.End - 2 Then Exit Do
    Loop
    End With
    ' Restore selection for user review
    rngS.Start = rngS.Start + 1 'adjust for manual line break
    rngS.Select
    Set rngS = Nothing
    End Sub</code>

  5. #5
    New Lounger
    Join Date
    Nov 2003
    Location
    Bloomington, Minnesota, USA
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Add Asterisk to selected lines (Word 2003 SP3)

    Hi-
    This is a big help. Our tedious task will be much easier with this macro. THANKS!

    p.s. I've been visiting here for a long time--since at least 2001, but rarely post.

Posting Permissions

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