PDA

View Full Version : Solved: Creating a VBA to save presentation



cmoore3984
10-12-2010, 10:01 AM
I have struggled for two days to get a presentation to save using VBA. I get multiple error messages that I don't understand and have googled everyway I can think. Basically, I have a macro that copies an excel spreadsheet into powerpoint using a VBA in Excel 2007 and now I want it to save the presentation when it is done. The program does a loop until active cell is empty then it exits. I want it to save the document when the loop is done.



Sub Copytoppt()


Do Until IsEmpty(ActiveCell)

There are a whole lot of commands inside the loop and they work. They were copied from a post inside this website -
Export Excel range or Excel chart to PowerPoint (linked or unlinked)
I just added a loop b/c the one sheet I copy changes 13 times and creates 13 slides in presentation.

ActiveCell.Offset(0, 1).Select

Loop

Here is where I want it to save. The loop is done, my 13 slides are created and I want to save presentation as powerpoint 2003 (.ppt). This VBA is saved in Excel 2007 if that matters.


End Sub

I appreciate any help I can get. I have spun my wheels for over 10 hours.

Cosmo
10-12-2010, 04:14 PM
Is this what you are looking for?
oPres.SaveAs filepath, ppSaveAsPresentation
oPres = the presentation you are saving (Application.ActivePresentation if you are saving the current file)
filePath = the full path (with filename) that you are saving the file to.


example:
application.ActivePresentation.SaveAs "C:\Documents and Settings\MyName\My Documents\Test.ppt", ppSaveAsPresentation

Paul_Hossler
10-12-2010, 05:15 PM
Cosmo, I don't have any test materials, but since it's an Excel 2007 macro that's running, wouldn't Application in


application.ActivePresentation.SaveAs


apply to Excel?

cmoore -- how are you opening PP, manually or is your Excel macro using CreateObject?


Paul

cmoore3984
10-13-2010, 05:28 AM
The only thing I have open is an Excel document and the VBA opens a powerpoint presentation then copies my sheet as a picture into a new slide (there are 13 variations to this one sheet = 13 slides).

When I use the above .SaveAs I get this message:

Run-time error '438':
Object doesn't support this property or method

I have googled this error but do not understand how to fix it.

Cosmo
10-13-2010, 05:42 AM
Sorry, Hadn't read that you were coming from Excel. You won't be able to use 'ppSaveAsPresentation' or 'application.activepresentation', but you should be able to Do you have a reference to the PowerPoint application in your excel document? Assuming that you do, and it's named "PPTApp", would this work:

PPTApp.SaveAs filepath, 1

cmoore3984
10-13-2010, 08:38 AM
This now gives me the error message -
Compile error:
Method or data memeber not found.
And it highlights the word SaveAs in your post.

I really appreciate your assistance...I think we are getting closer.

Cosmo
10-13-2010, 08:58 AM
This now gives me the error message -
Compile error:
Method or data memeber not found.
And it highlights the word SaveAs in your post.

I really appreciate your assistance...I think we are getting closer.

Cosmo
10-13-2010, 09:00 AM
Sorry about the blank posting, having problems with this forum; it didn't post my message properly, and won't let me edit it.

My previous code should have been:

PPTApp.ActivePresentation.SaveAs filepath, 1

cmoore3984
10-13-2010, 10:17 AM
It worked! Thank you so much for your help! It worked and I can finally close this portion of the project.





PPTApp.ActivePresentation.SaveAs filepath, 1

abhihyanki
03-12-2014, 02:02 AM
example:
application.ActivePresentation.SaveAs "C:\Documents and Settings\MyName\My Documents\Test.ppt", ppSaveAsPresentation


Hey Cosmo!!
Can you tell me if there's a way to directly save the presentation as a macro enabled one? (using ppSaveAsPresentation saves it in .ppt format)

John Wilson
03-12-2014, 09:02 AM
PowerPoint.Application.ActivePresentation.SaveAs _
"C:\Documents and Settings\MyName\My Documents\Test.pptm", ppSaveAsOpenXMLPresentationMacroEnabled

Should do it.

Paul_Hossler
03-12-2014, 02:14 PM
Can you tell me if there's a way to directly save the presentation as a macro enabled one? (using ppSaveAsPresentation saves it in .ppt format)


[QUOTE][
Here is where I want it to save. The loop is done, my 13 slides are created and I want to save presentation as powerpoint 2003 (.ppt).
/QUOTE]


2003 or 2007 macro enabled presentation? I don't know if there's any difference in PP, but Excel has a whole bunch of options to save in earlier versions

Paul

John Wilson
03-12-2014, 10:56 PM
Macro enabled presentations don't exist in 2003 Paul. It was introduced in 2007.

SamT
03-13-2014, 06:46 AM
Post dates, Paul, Post dates. :D