Link to home
Start Free TrialLog in
Avatar of agbnielsen
agbnielsen

asked on

Running a .ppta Powerpoint 2010 button gives a Run-Time error '5'

Hi All,

I have been creating and modifying a custom ribbon button in Powerpoint 2010 that uses a macro to save files to a location on the C: drive with a specific naming convention.

This had been working beautifully and I had tested it successfully many times. However I decided to create a new one using the steps at the below site:

http://stackoverflow.com/questions/3867400/how-to-add-tabs-to-powerpoint-2010-that-call-macros

I have created the pptm and modified it with Custom UI and, when I load the presentation, am able to successfully navigate to the custom tab and press the custom button and it does exactly what it is supposed to do. There is no problem with the XML code for the custom button and no problem with the macro.

However, when I save that presentation as a .ppta and add it as a powerpoint file, when I navigate to the custom tab/button and try and run it I get the following error:

Run-time error '5':
Invalid procedure call or argument

I have tried inserting this .ppta into Powerpoint 2010 on two other workstations and I get the same error when trying to run the macro. I have even tried creating it on another computer and the same thing happens; the .pptm with the macro and custom button works absolutely perfect, however when I save it as a .ppta I get the error.

Any help would be greatly appreciated.
Avatar of agbnielsen
agbnielsen

ASKER

Halp?!?!
Okay, so I have tried replacing the current macro, which is:

 
Sub SaveAsJPG()
    strPresentationName = Left(ActivePresentation.Name, InStrRev(ActivePresentation.Name, ".") - 1)
    strImageFolder = "C:\Daily Insight Report Files\"
    If Right(strImageFolder, 1) = "\" Then strImageFolder = Left(strImageFolder, Len(strImageFolder) - 1)
    If Dir(strImageFolder, vbDirectory) = "" Then MkDir strImageFolder
    blnContinue = False
    If Dir(strImageFolder & "\" & strPresentationName & "*.JPG") <> "" Then
        intResponse = MsgBox("Images for " & strPresentationName & " already exist. Do you want to overwrite?", vbYesNo, "Overwrite?")
        If intResponse = vbYes Then
            blnContinue = True
            Kill strImageFolder & "\" & strPresentationName & "*.JPG"
        End If
    Else
        blnContinue = True
    End If
    If blnContinue = True Then
        ActivePresentation.SaveAs strImageFolder, ppSaveAsJPG, msoFalse
        strFile = Dir(strImageFolder & "\Slide*.JPG")
        strFileList = ""
        While strFile <> ""
            Name strImageFolder & "\" & strFile As strImageFolder & "\" & strPresentationName & "_" & strFile
            If strFileList = "" Then
                strFileList = strPresentationName & "_" & strFile
            Else
                strFileList = strFileList & vbCrLf & strPresentationName & "_" & strFile
            End If
            strFile = Dir()
        Wend
        MsgBox "Files for " & strPresentationName & " have been created in " & strImageFolder & vbCrLf & strFileList
    Else
        MsgBox "Files have not been overwritten."
    End If
End Sub

Open in new window


with

 
Sub SayHello(ByVal control As IRibbonControl)
    MsgBox "hello"
End Sub

Open in new window


and that works after I add the.ppam into powerpoint. So I guess that means it is a problem with the macro.

Just to recap:

- I create the first macro and use Custom UI Tool to associate it with a custom tab/button. I then save it as a .pptm and can successfully click the button and run the macro.

- When I save that .pptm (which works) as a .ppam (powerpoint addin) it fails saying:

Run-time error '5':
Invalid procedure call or argument

- However when I substitute the first macro with the second, it works fine in both a .pptm and .ppta.

If anyone could please take a look at the code and perhaps try and recreate the issue (I have tried doing this on 3 separate workstations, and they all fail) and *hopefully* find an answer, well then I'm sure we could be best friends forever!

Thanks!!
Avatar of RobSampson
Hi, I haven't had a chance to test it yet, but have you tried changing this:
Sub SaveAsJPG()

to this:
Sub SaveAsJPG(ByVal control As IRibbonControl)

Rob.
Also, are you able to debug the project to see what line the error occurs on?
Check your Macro security before loading the add in.  When I had my macro security set to Disabled with notification, I couldn't see the code in the add-in.  But when I set it to Enabled, then restarted Powerpoint, loaded my presentation, then loaded the add in, the code worked fine.

Rob.
Hi Rob,

I have tried adding (ByVal control As IRibbonControL), however this does not fix the problem.

My macro security settings are set to able all macros.

One thing I forgot to mention was after the runtime error, I get:

"The macro cannot be found or has been disabled due to your security settings".

If you are unable to recreate the issue, perhaps you could shoot me over your .ppam and I could test that?

I'm not sure how to debug the project.

Cheers
So you can't run the code from the ribbon....can you click the Developer tab, then click Macros and run your code?
I can run the code from the ribbon, but only when I try to run the macro before I go to File > Options > Add-Ins and add the .ppam.

Everything works fine until I do that.

So, I can open two files: the original .pptm which has the macro/ribbon inserted - this works fine and the macro is called. I then save that as a .ppam. I can even load the .ppam directly through powerpoint (i.e. just double clicking it) and it complains about there being no active presentation, which is fine! It means the macro is working sweet. It's only when I load it as an add-in that I get the Run-Time Error 5.

When I go to the developer tab there is no macro listed. This is both on the original .pptm  (this is the one that works, and only brEaks after I go File > Save As > .ppam) and the .ppam.

Here is my XML code:

 
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<ribbon startFromScratch="false">
		<tabs>
			<tab id="CustomTab" label="Daily Insight Reports">
				<group id="customGroup" label="Export">
					<button id="CustomButton" label="Daily Insight Reports" image="n_logo" size="large" onAction="SaveAsJPG" />
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

Open in new window


I looked at the threads you mentioned, and created two new .XMLs for testing, both work fine before I add it as a powerpoint add-in, but break after that.

 
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
	<ribbon>
		<tabs>
			<tab id="CustomTab" insertAfterMso="TabHome" label="Daily Insight Reports">
				<group id="customGroup1" label="Export">
					<button id="CustomButton1" onAction="SaveAsJPG" imageMso="DoubleBottomBorder" label="Double Bottom" />
				</group>
			</tab>
		</tabs>
	</ribbon>
</customUI>

Open in new window


This is so frustrating :(
I'm having a heck of a time trying to get the Custom UI to even show up in Powerpoint.  I add the XML to the PPTM and when I open it, I can't find my newly added ribbon.....I can't figure out what I'm doing wrong at the moment....
OK, it's finally come up....I had to use this for Powerpoint 2007:
xmlns="http://schemas.microsoft.com/office/2006/01/customui"

but I now get the same error as you....I'll look into it now....
Great, thanks! Happy we are on the same page.
OK, here's something interesting!  On Windows XP it worked perfectly!  On Windows 7, I get the same error!!!  Permissions maybe....
Ah.... never even thought of that. I am using Windows 7, I will test on an XP box now.
So it works on Windows XP!!

But this is the strange thing, it DID work on Windows 7. I made it on my computer and did all the testing, but now it doesn't work.

Perhaps it is an update that recently got installed? The problem is that I will definately need this to work on Windows 7 :(
OK, try this.

Click the Office button
Powerpoint Options
Trust Center
Trust Center Settings
ActiveX Settings
Select the "Enable all controls without restrictions and without prompting" option and click OK.

My original setting was "Prompt me before enabling all controls with minimal restrictions", and I also had "Safe mode" selected (which I didn't change).

The strange this is, the same settings are on my Windows XP machine, yet it worked without change, whereas on Windows 7, I had to change that ActiveX Setting.

Rob.
My guess there was an ActiveX killbit in a recent patch or something...
Wait....WHAT?!?!??!!?  It only worked the first time!!!!  Now that I've restarted Powerpoint, it won't work on Windows XP or Windows 7!!
Not sure whether to laugh or cry??

I had already played with the ActiveX controls and I had it set to "Enable all controls with minimal restrictions", so that doesn't work. I didn't have safe mode selected though, so I enabled that.

Still same problem though.

How bizzare.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you verify the following registry states:

Key: HKCU\Software\Microsoft\Office\14.0\Powerpoint\Security
Value: AccessVBOM
Data: 1

Key: HKCU\Software\Microsoft\Office\14.0\Powerpoint\Security
Value: VBAWarnings
Data: 1

That's what mine is at the lowest security.

Make sure you don't have any of the same value under HKLM instead of HKCU, because they will override it.

Rob.
Wow, I am a bloody idiot!

I was never using a saved presentation. I will simply opening up powerpoint and doing it from there. When I save a presentation, then open itm the button works fine.

Thanks for your help (again). Just needed this back and forth to figure it out.

Yeah, I made that mistake too!  So it worked all along???  Doh!!!

LOL!  Oh well, at least we got there!

Rob.
Yeah, worked perfectly all along. Thanks Bud.
OK, after all that, I now know what the problem is.  Since the presentation has not been saved, ActivePresentation.Name does not have a dot in it, so an error occurs.  I have just added an If statement to check if the presentation has a dot in it.

Rob.
Sub SaveAsJPG(ByVal control As IRibbonControl)
    If InStr(ActivePresentation.Name, ".") > 0 Then
        strPresentationName = Left(ActivePresentation.Name, InStrRev(ActivePresentation.Name, ".") - 1)
        strImageFolder = "C:\Daily Insight Report Files\"
        If Right(strImageFolder, 1) = "\" Then strImageFolder = Left(strImageFolder, Len(strImageFolder) - 1)
        If Dir(strImageFolder, vbDirectory) = "" Then MkDir strImageFolder
        blnContinue = False
        If Dir(strImageFolder & "\" & strPresentationName & "*.JPG") <> "" Then
            intResponse = MsgBox("Images for " & strPresentationName & " already exist. Do you want to overwrite?", vbYesNo, "Overwrite?")
            If intResponse = vbYes Then
                blnContinue = True
                Kill strImageFolder & "\" & strPresentationName & "*.JPG"
            End If
        Else
            blnContinue = True
        End If
        If blnContinue = True Then
            ActivePresentation.SaveAs strImageFolder, ppSaveAsJPG, msoFalse
            strFile = Dir(strImageFolder & "\Slide*.JPG")
            strFileList = ""
            While strFile <> ""
                Name strImageFolder & "\" & strFile As strImageFolder & "\" & strPresentationName & "_" & strFile
                If strFileList = "" Then
                    strFileList = strPresentationName & "_" & strFile
                Else
                    strFileList = strFileList & vbCrLf & strPresentationName & "_" & strFile
                End If
                strFile = Dir()
            Wend
            MsgBox "Files for " & strPresentationName & " have been created in " & strImageFolder & vbCrLf & strFileList
        Else
            MsgBox "Files have not been overwritten."
        End If
    Else
        MsgBox "The presenation has not been saved.  Please save it to use this feature."
    End If
End Sub

Open in new window

Above and beyond! Thanks, I'll recode that, and I'll shout you a beer one day.