macro in powerpoint add-in cannot be activated although add-in is loaded along with low macro security setting

Dear Experts

I have created a ppam file that contains a macro. The macro works fine. I also created a custom command button on the ribbon for the macro.

I have loaded the add-in manually thru the regular 'load available add-ins' dialog box.

I also set the macro settings to: enable all macros (not recommend; potentially dangerous code can run)

So everything is fine. But still,  if I run the macro thru the user-defined macro button I keep getting the following message box:

The macro cannot be found or cannot be run because of your macro security settings.

I am pretty sure the add-in has been loaded (because it shows under options - add ins PowerPoint Add-ins), but the macro in that add-in somehow cannot be activated.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?
 
Jamie GarrochConnect With a Mentor PowerPoint Consultant & DeveloperCommented:
I confirmed that the method you're using won't work as expected. I created a test pptm file with a test macro. I then added a command to that macro using the backstage Customize Ribbon functionality. Having saved the file as a ppam and loaded it as an add-in I then exported the ribbon customisation (File / Options / Customize Ribbon / Import/Export) and looked at the XML it generated. This is the snippet for the new button:

<mso:group id="mso_c1.66956DC" label="New Group" autoScale="true">
	<mso:button idQ="x1:_Custom_Button_Test.pptm__Test_0_66EAE79"
		label="'Custom Button Test.pptm'!Test"
		imageMso="ListMacros"
		onAction="'Custom Button Test.pptm'!Test"
		visible="true"/>
</mso:group>

Open in new window


You can see that the onAction callback is referring to the pptm file and not a ppam file. That's why you're getting the error because the button's XML callback is looking for the macro in the wrong file. So, once the code is in an application add-in, there appears to be no way to reference is using the backstage Customize Ribbon UI. The root of the issue is that you're creating the custom button in the PowerPoint UI customisation and not inside your project file.I'd recommend using the CustomUI Editor as mentioned above or the free version of Visual Studio so that the customUI part travels with the pptm and corresponding ppam files.
0
 
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
That message is a very generic and misleading one from Microsoft. It "can" be triggered as it says due to macro security but it can also be generated if your customUI XML callback does not match the expected callback signature in your VBA. What is the XML you are using for the button and what is the callback signature you have e.g.

XML

<button id="myButton" onAction="OnAction"/>

Open in new window


VBA

Public Sub OnAction(control As IRibbonControl)
  Select Case control.id
    Case "myButton": 'Do stuff
    Case Else: Debug.Print "OnAction not handled for : " & control.id
  End select
End Sub

Open in new window

0
 
Andreas HermleTeam leaderAuthor Commented:
Hi Jamie,

thank you very much for your swift and very professional help.

Uppps, you are telling me that the command button on the ribbon can only be made thru XML coding.

I just did it with the built-in 'customize ribbon' functionality.
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Andreas HermleTeam leaderAuthor Commented:
I am off to catch my train. Any comments from you, Jamie or other experts, I will only be able to address later tonight.

Thank you
0
 
Jamie GarrochConnect With a Mentor PowerPoint Consultant & DeveloperCommented:
I know you can use that method to add a custom button for a macro in the active presentation (.pptm) but I don't think that can be made to work for a .ppam But, if you can write macros, adding XML to your project isn't that difficult. You can do it manually by adding a customUI.xml file in a customUI folder in the root of the ZIP archive of the pptm file (rename it .zip, unzip, edit the contents, rezip, rename to .pptm) or you can download the free CustomUI Editor (Google it) and just add the code like below:

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab id="myTab" label="My Tab">
        <group id="myGroup" label="myGroup">
          <button id="myButton" label="myButton" onAction="OnAction"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

Open in new window

0
 
Andreas HermleTeam leaderAuthor Commented:
Wow what a superb support!!!
Incredible
Thank u very much

Will award points tomorrow ...
0
 
Andreas HermleTeam leaderAuthor Commented:
Hi Jamie,

thank you very much for your swift and very professional help. This is superb support from your side.

I now know that  the built-in functionality just won't work in my case. I will know try to do some programming with the Custom UI Editor.

Again, thank you very much for your great support.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.