Results 1 to 6 of 6
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application.Caller (Word 97, NT 4.0)

    Hi Guys

    I asked the Excel list this on Friday when my brain was fried, and guess what, .... the weekend did not magically deposit the knowledge that I need, and apparently the same is true of the Excel guys... no joy from that august group ;+{

    I am trying to find an equivalent command to Excel's Application.Caller in MSWord. I want to use it to identify the source button on a custom menu created dynamically by VBA. Each button will point to the same macro, and I will use Application.Caller (or its equivalent) to distinguish the specific button and take the appropriate action based on the button caption.

    Anyone run into an equivalent to Application.Caller before that can set my mind on the right track?

    TIA

    Jim Byrne

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Application.Caller (Word 97, NT 4.0)

    I had a similar query: how would my Save and SaveAs event handlers know if the user called them directly or through a FileClose command? Hmmm...

    Anyway, here is the answer to your question, I believe, and it is generalizable across Office because it uses the CommandBar object model:
    <pre>Sub CBarReporter()
    Dim cbCtrl As CommandBarControl
    Set cbCtrl = CommandBars.ActionControl
    If cbCtrl Is Nothing Then
    MsgBox "This macro was invoked other than through a command bar."
    Else
    MsgBox "You pressed the button captioned " & cbCtrl.Caption
    Set cbCtrl = Nothing
    End If
    End Sub</pre>

    I used the .Caption property for this demo, but you can use the .Tag property as well.

    Tested on Word 2000 only. Hope this works for you!
    Attached Files Attached Files

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Application.Caller (Word 97, NT 4.0)

    Hi,

    From <post#=240050>post 240050</post#> you guided me to this post and I have tried the procedure described, but can't get it working. I'm not an experienced VBA programmer so I need some explanation of what the procedure is doing and if there are any conditions for it to work.

    I placed the procedure in ThisDocument and its command in my Private Sub FileSave(), also placed in ThisDocument, which is intercepted when I click File/Save. The CBarReporter procedure is running but this is only giving me that the Commandbar.ActionControl is Nothing whether I have clicked the save button or the File/Check in (Command ID Ch&eck In = 6128).

    Can't understand how the procedure can get the name (Caption) of the button or built in macro when clicked?

    If there could be a macro that is acting when using the File/Check in or e.g. File/Save, it would have solved my problem. E.g.: Check-in_Click()


    I may me far off from understanding VBA!

    Bjorn

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Application.Caller (Word 97, NT 4.0)

    You need to replace the regular Save Menu item with the button which says the same thing.

    Do this by choosing Tools > Customize and dragging the macro into the same location as the File Save menu item.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Application.Caller (Word 97, NT 4.0)

    My sincerest apologies. This does not seem to work for built-in commandbar controls. The online help says:

    Returns the CommandBarControl object whose OnAction property is set to the running procedure.
    If the running procedure was not initiated by a command bar control, this property returns Nothing.

    What seems to be missing is "For controls whose OnAction property is blank (e.g., built-in commandbar controls), this property returns Nothing."

    No other solution comes readily to mind. Bummer.

  6. #6
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    ASKER, Norway
    Posts
    277
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Re: Application.Caller (Word 97, NT 4.0)

    Hi,

    You don't have to apologize, it is me who is not a good enough VBA programmer.

    I understand it such that I cannot use the procedure "CBarReporter" for built-in commands whether they are located in the menu or are located in a toolbar.

    If I should use it I have to use the Nothing value. But both the "Check in" command and the "Save" command gives Nothing as a return value. So I cannot distinguish between the two commands.

    Using what Andrew suggest and replacing the regular "Save" button with a custom button when that particular template is used might solve the problem (?????)

    Well, thanks to both of you. I have got something more to test.....


    bjorn

Posting Permissions

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