Consulting

Results 1 to 4 of 4

Thread: [VBA MS Word] Code to control BeginArrow and EndArrow

  1. #1
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location

    [VBA MS Word] Code to control BeginArrow and EndArrow

    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.

    macro_arrow.jpg

    Any help would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Newbie
    Joined
    Nov 2016
    Posts
    2
    Location
    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.

    macro_arrow2.jpg
    Attached Files Attached Files

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    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.
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

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