PDA

View Full Version : [VBA MS Word] Code to control BeginArrow and EndArrow



blueantz
11-16-2016, 07:31 PM
Stumped trying to get code to work that will control BeginArrow and EndArrow types based on selection by user.

For example, if user selects "heads", begin arrow type ="no arrow" and end arrow type = "arrow" with arrow size 9.

If user selects "tails", begin arrow type ="arrow" and end arrow type = "no arrow" with arrow size 9.

17622

Any help would be greatly appreciated.

gmaxey
11-16-2016, 08:18 PM
You can't set size to 9. You have to use one of the available constants:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
'Select your line and name it with this code:
Selection.ShapeRange(1).Name = "Line"
'Then stet out that line and process with:
With ActiveDocument.Shapes("Line").Line
If "heads" = "heads" Then
.BeginArrowheadStyle = msoArrowheadNone
.EndArrowheadStyle = 2
.EndArrowheadLength = msoArrowheadLong
Else
.EndArrowheadStyle = msoArrowheadNone
.BeginArrowheadStyle = 2
.BeginArrowheadLength = msoArrowheadLong
End If
End With
lbl_Exit:
Exit Sub
End Sub

blueantz
11-17-2016, 04:11 AM
Hi Greg,

My situation at work is that I already have a word document with objects and line shapes already in place. Is it possible to add a macro to these existing shapes to add the begin arrow or end arrow, based on the user selection.

For example, the decision tree is based on the objects on the left hand side. If the team on the left side is the winner, the begin arrow would be pointing to the team on left hand side. If the team on the left side is the loser, the end arrow would be pointing to the team on right hand side.

17634

gmaxey
11-17-2016, 04:53 AM
Shapes don't have macros. You can name them as I have already shown you but you are going to have to have something to use make the selection.