Consulting

Results 1 to 8 of 8

Thread: Word VBA: Passing Arguments from click on Macrobutton IN REVIEWING PANE

  1. #1
    VBAX Regular
    Joined
    Feb 2017
    Posts
    12
    Location

    Word VBA: Passing Arguments from click on Macrobutton IN REVIEWING PANE

    What I'm using: Word For Mac 2011

    What I am trying to: Insert programmatically IN THE REVIEWING PANE, IN A COMMENT, a macrobutton field that when clicked passes an argument to global macro. Yes, I know that Macrobutton cannot natively pass arguments. For workarounds, I reviewed a helpful post on wordmvp which can be viewed searching google for "wordmvp using macro button"

    The code below works fine in the main body of the Agreement. But it does not work in when the macrobutton field is entered into a comment (I am viewing comments and testing this code via the Reviewing Pane). The reason it doesn't work *appears* to be that WORD can't see the nested private field in the reviewing pane (again, Word sees private field just fine in document section).

    I have also tried using "AddIn" field, but that too doesn't appear to work for Macrobutton field inserted into a Comment either (Again, second field appears to be unreadable when in comment/reviewing pane). My problem may be in the subroutine named ShowHiddenFieldData, and the Selection.fields(2) line because selection objects seem to be unstable in the comments/Reviewing Pane. I also note there seems to be some instability in toggling fields codes in the reviewing pane. Advice would be appreciated.

    Two Questions: (1) Can any of you repeat my error in Word (PC - any version)? That is, first move cursor to place in main document, run test_InsertNestedField to insert MacroButton field with nested Private field, then double click on Macrobutton to run ShowHiddenFieldData macro which should return the "hidden" text from the Private field nested in the Macrobutton field. This should work just fine. Then click "Insert Comment" and in the reviewing pane, repeat the steps again. This is not working; I get "run time error 5941 Requested Member of Collection Does not Exist."

    (2) If you can repeat my error, please suggest some work-arounds or alternatives. I need to be able to insert dozens of these macrobuttons in the COMMENTS SECTION, and when the buttons are clicked I need to pass an ID number to a macro that will use that ID to fetch data that will then populate a user form for further action by the user. (e.g. in comment #14, Macrobutton "Click Here to See detailed rules and policies about X")

    ========Code: following below are three (3) separate sub-routines

    Function Function_InsertPrivateWithinMacroButton2(PrivateText As String, PublicText As String)
    Dim MyField1 As Field
    Dim MyField2 As Field


    ActiveWindow.View.ShowFieldCodes = False
    ActiveWindow.View.ShowHiddenText = False
    Application.ScreenUpdating = False


    Set MyField1 = ActiveDocument.Fields.Add(Range:=Selection.Range, Type:=wdFieldEmpty, preserveformatting:=False)
    MyField1.Code.Select
    Selection.Characters.First.Delete
    MyField1.Code.Select
    Selection.Collapse wdCollapseEnd
    Selection.TypeBackspace
    Selection.InsertAfter "Private " & PrivateText


    Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend


    Set MyField2 = ActiveDocument.Fields.Add(Range:=Selection.Range, Type:=wdFieldEmpty, preserveformatting:=False)
    MyField2.Code.Select
    Selection.Characters.First.Delete
    MyField2.Code.Select
    Selection.Collapse wdCollapseEnd
    Selection.TypeBackspace
    Selection.InsertAfter "MACROBUTTON ShowHiddenFieldData " & PublicText


    MyField2.Update
    MyField2.Select
    Selection.Collapse wdCollapseEnd
    Application.ScreenUpdating = True
    End Function
    ' ============ Sub-Routine 2 below

    Sub test_InsertNestedField()


    Dim PrivateText As String
    Dim PublicText As String


    PrivateText = "This is PRIVATE Text."
    PublicText = "Double Click Here to launch ShowHiddenFieldData macro"
    Function_InsertPrivateWithinMacroButton2 PrivateText, PublicText




    End Sub‹

    ' ============ Sub-Routine 3 below


    Sub ShowHiddenFieldData()
    ' This subroutine tests the presence of the private field supposed to be hidden as nested field with macrobutton
    Dim MacroData As String

    MacroData = Selection.Fields(2).Code
    Msgbox ("Unparsed Macro Data is " & MacroData)



    End Sub

  2. #2
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    It appears to me that macrobutton fields simply can't be triggered from the Reviewing Pane.
    Greg

    Visit my website: http://gregmaxey.com

  3. #3
    VBAX Regular
    Joined
    Feb 2017
    Posts
    12
    Location
    Greg: I cannot accept "no" as an answer.

    First, I am NOT having trouble launching a macro from a Macrobutton Field inserted in a comment. The problem I have run into is reading the second field in a nested field, where the subservient field intended to hold data is either a Private Field or an AddIn Field. I was experimenting with a Macrobutton nested with a second Macrobutton, where the second Macro button didn't have any display text, and I was attempting to "store" an argument in the "name" of the macro... but I ran into trouble with this because I couldn't get the outside field's macro to fire on the double-click.

    Let me ask this: Have you ever written code that does action on content within a comment? Have you ever tried to use selection.moveright, etc., to select text within a comment? If I could figure out the right syntax that allows me to modify the internal contents of a comment, I would be on the right track to finding a solution to my issue... As always, your help is appreciated.

  4. #4
    VBAX Regular
    Joined
    Feb 2017
    Posts
    12
    Location
    I should also note that I've tried bounding the macrobutton within a bookmark (in a comment viewable in Reviewing Pane), and then tried on the double-click firing of the Macro to return the bookmark from the selection, but again, had trouble making that work in the reviewing pane.... There has got to be a way to make this happen

  5. #5
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    I'm not having trouble launching a macro from a macrobutton field inserted in a comment either. The trouble is that macrobutton fields that are in comments, while they trigger just fine from the comment balloons in the document, simply don't trigger from the reviewing pane.

    The following works just fine from the comment balloons.

    { { Private 100 } MacroButton MBWArg "Dbl-Cick" }

    Sub MBWArg()
    Dim lngCount As Long
    'Ignore first 9 characters of the private field the word 'Private', and the spaces
    lngCount = CLng(Mid$(Selection.Fields(2).Code, 9))
    MsgBox lngCount
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  6. #6
    VBAX Regular
    Joined
    Feb 2017
    Posts
    12
    Location
    Yes, I see the same. In that case, how would I code the VBA equivalent of "If user clicks this macro button in Reviewing Pane, show a msgbox ("you must view comments as balloons to use this feature"), and then turn off reviewing pane and turn on balloons"?

  7. #7
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,335
    Location
    As I have tried to explain and you seemed to have understood, a click on a macrobutton field in the reviewing pane is not detected so there is no VBA equivalent of clicking a macrobutton field in the reviewing pane. You might create SelectionChange event and use it to detect whether the review pane is displayed:

    or maybe the document open event.

    Sub Document_Open()
    If ActiveWindow.View.SplitSpecial = 18 _
    Or ActiveWindow.View.SplitSpecial = 19 _
    Or ActiveWindow.View.SplitSpecial = 20 Then
    MsgBox "Tell the user to turn off Revisions Pane and review comments as inline balloons."
    End If
    End Sub
    Greg

    Visit my website: http://gregmaxey.com

  8. #8
    VBAX Regular
    Joined
    Feb 2017
    Posts
    12
    Location
    Greg - Thank you so much. This is very helpful.

Tags for this Thread

Posting Permissions

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