Consulting

Results 1 to 7 of 7

Thread: Solved: WORD 2010 Custom UI Callbacks not working

  1. #1
    VBAX Regular
    Joined
    Feb 2010
    Posts
    11
    Location

    Unhappy Solved: WORD 2010 Custom UI Callbacks not working

    I have created a Word template which I am loading as a add-in with custom UI ribbon buttons,

    These buttons SHOULD call macros which are in the template however none of them "fire" - I have tried everything I can think of and have spent a couple of hours trawling the web to no avail

    Attached is the document (in zip file)

    Two of the Macros are "addprotection" &"removeprotection" (these are the easiest to test) - All they do is enable document protection with a password.

    If anybody can help me to get thse to work I would appreciate it.

    The callback code is as follows (this is within a module):


    [vba]
    'Callback for Addprotection onAction
    Sub Addprotection(control As IRibbonControl)

    End Sub

    'Callback for RemoveProtection onAction
    Sub RemoveProtection(control As IRibbonControl)

    End Sub

    'Callback for MergeSaveSplit onAction
    Sub MergeSaveSplit(control As IRibbonControl)

    End Sub

    'Callback for SplitandSave onAction
    Sub SplitandSave(control As IRibbonControl)

    End Sub
    [/vba]
    Attached Files Attached Files

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    There are problems with your file.

    That being said, if the code you posted is accurate - "
    The callback code is as follows (this is within a module)

    then it is no surpriase they do not "fire". There is nothing there TO fire. You may as well have:
    [vba]Sub GiraffeCoffeeDrinker(oDoc as Document, Elephants as Elephant)
    End Sub[/vba]

    1. There are NO instructions in the procedure...tell me to do nothing, and that is what I will do.

    2. They have parameters, so they need to be called from some OTHER procedure to fire anyway.

  3. #3
    VBAX Regular
    Joined
    Feb 2010
    Posts
    11
    Location
    Hi Fumei, You have said there are problems with my file - Please could you elaborate on what you are meaning (I have attached a .Docm version rather than the Zipped Dotm file I submitted originally Tools2.docm) - If it is problems which are stopping you opening it etc then if I know what they are I can try and sort them out. I get no error messages etc when I open either file.

    In terms of your response to my code I feel I was obviously not specific enough in my original post:

    The VBA I posted was the "bare bones" - these are the callbacks that the "Custom UI editor" program gave me - I have tried the following to get them to work:

    I have tried to call my macros within these for example:

    [vba]'Callback for Addprotection onAction
    Sub Addprotection(control As IRibbonControl)

    Call macro1

    End Sub[/vba]
    I have tried to place my macro code directly into the procedures:

    [vba]'Callback for Addprotection onAction
    Sub Addprotection(control As IRibbonControl)

    On Error GoTo leave

    Sections = ActiveDocument.Sections.Count

    For x = 1 To Sections

    ActiveDocument.Sections(x).ProtectedForForms = True
    Next x


    ActiveDocument.Protect Password:="randompasswordhere", NoReset:=False, Type:= _
    wdAllowOnlyFormFields, UseIRM:=False, EnforceStyleLock:=False


    leave: Exit Sub

    End Sub[/vba]

    I have done both the above steps from within modules & also by putting the callbacks into the "ThisDocument" rather than a module

    I have tried to make all routines (In various combinations) Public (As in "Public Sub" rather than just "Sub")

    If I create a custom ribbon tab and insert Macros into this they work fine - the problem is trying to do this as part of a add-in.

    The XML code I am using to create the custom Ribbon tab is as follows:

    PHP Code:
    <mso:customUI xmlns:x1="http://schemas.microsoft.com/office/2009/07/customui/macro" xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
    <
    mso:ribbon>
    <
    mso:qat/>
    <
    mso:tabs>
    <
    mso:tab id="mso_c2.1FF68E" label="Useful Stuff" insertBeforeQ="mso:TabAddIns">
    <
    mso:group id="mso_c3.1FF68E" label="New Group" autoScale="true">
    <
    mso:button idQ="x1:Addprotection" size="large" label="Add Protection" imageMso="Lock" onAction="Addprotection" visible="true"/>
    <
    mso:button idQ="x1:RemoveProtection" size="large" label="Remove Protection" imageMso="AdpPrimaryKey" onAction="RemoveProtection" visible="true"/>
    <
    mso:button idQ="x1:MergeSaveSplit" size="large" label="Merge &amp;&amp; Split" imageMso="EquationOptions" onAction="MergeSaveSplit" visible="true"/>
    <
    mso:button idQ="x1:SplitandSave" size="large" label="Split Premerged" imageMso="QueryUnionQuery" onAction="SplitandSave" visible="true"/>
    </
    mso:group>
    </
    mso:tab>
    </
    mso:tabs>
    </
    mso:ribbon>
    </
    mso:customUI
    Any further help would be appreciated.

  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    You have several issues involved here. First as Fumei mentioned, your callbacks are empty. Even if they did fire, who would know it?

    Change you callback to this:

    [VBA]Sub ButtonOnAction(control As IRibbonControl)
    MsgBox control.ID
    Select Case control.ID
    Case "Addprotection"
    PasswordProtect.Addprotection
    Case "RemoveProtection"
    PasswordProtect.RemoveProtection
    Case "SplitandSave"
    'Call as appropriate.
    Case "MergeSaveSplit"
    'Call as appropriate.
    End Select
    End Sub
    [/VBA]

    Change all of you onAction attributes in the XML script to this:

    "Callbacks.ButtonOnAction"

    Get rid of the iqQ="xl.whatever"
    and replace with id="whatever"

    for all of the buttons. idQ does not work with button commands.
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Regular
    Joined
    Feb 2010
    Posts
    11
    Location
    Hi Greg, That's great got it all to work now.

    Before seeing your response I actually tried to use the guide on your website

    http://gregmaxey.mvps.org/word_tip_p...bbon_main.html

    I got it all sorted (or so I thought) However there was something in there which was causing the Macros to be blocked (even when setting all security as low as possible) - But this code has worked great.


    In regards to my XML - Thats because I created the custom ribbon then exported it and pulled the XML out of the export file. - Suppose its the same as recording Macros - You always end up with spacefiller/It never runs right again.

    Don't know how many more languages I can fit in my head what with VBA, HTML, XML - I have a hard enough time with English and I am from England.

  6. #6
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,340
    Location
    Ed,

    Check your Word Options>Advanced>General and made sure that Show Add-in interface errors is checked. Sometimes an unflagged error regardless of how small can tear down the whole house of cards.
    Greg

    Visit my website: http://gregmaxey.com

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    1. You can remove the <mso:qat/> - the QAT can only be customized in startFromScratch mode

    2. You have a module called MergeSaveSplit and a sub called MergeSaveSplit. I've always found that's a good way to confuse VBA.

    3. For something like this, do you really need to use 2 namespaces?

    4. I like to use Option Explicit at the top of all modules

    5. I don't think Word has the 'add in' the way Excel has .xlam's. I just put such Tool templates in one of the Word start up folders. I usually use C:\Users\<userid>\AppData\Roaming\Microsoft\Word\STARTUP\Tools.dotm


    Paul

Posting Permissions

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