PDA

View Full Version : Anchor graphics line to paragraph



YossiD
11-08-2016, 07:40 AM
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.

17534

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.

17535

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.

gmaxey
11-08-2016, 06:19 PM
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?

YossiD
11-09-2016, 12:39 AM
Document attached.

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



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?

gmaxey
11-09-2016, 07:06 PM
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

YossiD
11-13-2016, 04:28 AM
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