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 && 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.