[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-17
27
Medium Priority
?
931 Views
Last Modified: 2012-05-12
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.
0
Comment
Question by:agbnielsen
  • 15
  • 12
27 Comments
 

Author Comment

by:agbnielsen
ID: 37004392
Halp?!?!
0
 

Author Comment

by:agbnielsen
ID: 37055095
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!!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37061541
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 65

Expert Comment

by:RobSampson
ID: 37061547
Also, are you able to debug the project to see what line the error occurs on?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37061598
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.
0
 

Author Comment

by:agbnielsen
ID: 37061788
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
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37061986
So you can't run the code from the ribbon....can you click the Developer tab, then click Macros and run your code?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37062055
0
 

Author Comment

by:agbnielsen
ID: 37066719
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 :(
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067665
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....
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067689
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....
0
 

Author Comment

by:agbnielsen
ID: 37067694
Great, thanks! Happy we are on the same page.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067695
OK, here's something interesting!  On Windows XP it worked perfectly!  On Windows 7, I get the same error!!!  Permissions maybe....
0
 

Author Comment

by:agbnielsen
ID: 37067698
Ah.... never even thought of that. I am using Windows 7, I will test on an XP box now.
0
 

Author Comment

by:agbnielsen
ID: 37067721
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 :(
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067732
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.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067734
My guess there was an ActiveX killbit in a recent patch or something...
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067741
Wait....WHAT?!?!??!!?  It only worked the first time!!!!  Now that I've restarted Powerpoint, it won't work on Windows XP or Windows 7!!
0
 

Author Comment

by:agbnielsen
ID: 37067744
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.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 37067751
Ah, no....that was my fault....I didn't have a saved presentation open.

So, with a saved presentation open, with multiple slides, it works on Windows 7 for me now.  Interestly, and bizarrely, I have since set my ActiveX settings back to what they used to be, restart Powerpoint, load my test pptx, and the button still works....

I'm running as an Admin user.  Does it make any difference if you browse to C:\Program Files\Microsoft Office\Office, right click Powerpnt.exe and click Run As Administrator?

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067757
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.
0
 

Author Comment

by:agbnielsen
ID: 37067761
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.

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067763
Yeah, I made that mistake too!  So it worked all along???  Doh!!!

LOL!  Oh well, at least we got there!

Rob.
0
 

Author Comment

by:agbnielsen
ID: 37067768
Yeah, worked perfectly all along. Thanks Bud.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37067794
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

0
 

Author Comment

by:agbnielsen
ID: 37067808
Above and beyond! Thanks, I'll recode that, and I'll shout you a beer one day.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question