Consulting

Results 1 to 5 of 5

Thread: Anchor graphics line to paragraph

  1. #1
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location

    Anchor graphics line to paragraph

    I need to add revision marks showing changes to a table of action items for a project. The first column of the table contains the action item number and the second various descriptive text. In my case, using Word's Track Changes doesn't do the trick because the table extends into the margin so the revision marks end up inside the table. I could change the margins, but there's another problem.

    The rows in the table contain several short paragraphs of text. The change marks of Track Changes indicate the entire row, and not just the changed line(s), which rather defeats the purpose of the change marks.

    So instead of using Track Changes, I decided to use graphic lines as revision marks to show where the changes are . Here's how the table looks when I add the revision marks manually. The line is anchored to the changed paragraph and moves with the paragraph if I enter more paragraphs of text above it.

    Table Rev Marks 1.jpg

    Obviously, adding these marks manually is quite a nuisance, especially if there are many of them.

    I have created the following macro as a workaround. With only trial and error VBA experience, this might not be the best code, but it does work.

    Sub RevLine()
     Dim lineNew As Shape
    'Get vertical position of cursor (insertion point)
     Location = Selection.Information(wdVerticalPositionRelativeToPage)
    'Add a line to the drawing
     Set lineNew = ActiveDocument.Shapes.AddLine( _
     BeginX:=40, BeginY:=Location, EndX:=40, EndY:=Location + 15)
    'Lock the anchor
     lineNew.LockAnchor = True
    'Set line weight and color
     With lineNew.Line
     .Weight = 1.5
     .ForeColor.RGB = RGB(Red:=0, Green:=0, Blue:=0)
     
     End With
    End Sub
    This works ok, except that the revision mark gets anchored to the number in the first column rather than to the changed paragraph, even though the editing cursor (insertion point) is in the changed paragraph when I invoke the macro. Here's what the result looks like.

    Table Rev Marks 2.jpg

    With this result, if I insert an additional paragraph before the changed one, the revision mark doesn't move with it. In addition, the vertical alignment of the number in the first column has changed to top aligned.

    Is there anything I can do in the macro to force the revision line to anchor to the changed paragraph?

    Thanks.

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    I created a table similar to yours and put the cursor in line four ("Harvey") of the second column, ran your code and it worked fine.

    Can you attach your document?
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location
    Document attached.

    I should probably mention that I am using Word 2003 SP3 (I can't stand the ribbons).


    Quote Originally Posted by gmaxey View Post
    I created a table similar to yours and put the cursor in line four ("Harvey") of the second column, ran your code and it worked fine.

    Can you attach your document?
    Attached Files Attached Files

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    Yep, that has something to do with it. Try this:

    Option Explicit
    Sub RevLine()
    Dim oShpLine As Shape
    Dim lngPosit As Long
      'Get vertical position of cursor (insertion point)
      lngPosit = Selection.Information(wdVerticalPositionRelativeToPage)
      'Add a line to the drawing
       Set oShpLine = ActiveDocument.Shapes.AddLine( _
       BeginX:=40, BeginY:=lngPosit, EndX:=40, EndY:=lngPosit + 15, Anchor:=Selection.Paragraphs(1).Range)
       'Lock the anchor
       oShpLine.LockAnchor = True
       'Set line weight and color
       With oShpLine.Line
         .Weight = 1.5
         .ForeColor.RGB = RGB(Red:=0, Green:=0, Blue:=0)
       End With
    lbl_Exit:
      Exit Sub
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular YossiD's Avatar
    Joined
    Jan 2009
    Posts
    33
    Location
    That fixed the anchor point, but the line is now appearing in the wrong position. I will play with this a bit when time allows, and let you know what happens.

    Thanks

Posting Permissions

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