PDA

View Full Version : Solved: VBA to Save PowerPoint



JimS
04-26-2011, 12:06 PM
The following code was borrowed from another workbook and was working but for some reason it now fails with a Compile Error - it highlights the word "Date" in the "fNamef =" line.

Any ideas why this no longer works?

Thanks...

JimS


Sub Save_PPT()

Dim oPPTApp As PowerPoint.Application
Dim oPPTFile As PowerPoint.Presentation
Dim sPath, fName1, fNamef As String

sPath = "C:\MyData1 \"
fName1 = "Sample_Data"
fNamef = fName1 & "_" & Format(Date, "mmm-dd-yyyy") & "_" & Format(Time, "hh-mm-ss") & ".ppsm"

Set oPPTApp = CreateObject("PowerPoint.Application")
oPPTApp.Visible = msoTrue

Set oPPTFile = oPPTApp.ActivePresentation

oPPTApp.Visible = msoTrue

oPPTFile.SaveAs Filename:=sPath & fNamef, FileFormat:=ppSaveAsDefault

oPPTFile.Close
oPPTApp.Quit

End Sub

Bob Phillips
04-26-2011, 12:16 PM
I don't know why Date is failing, but why not just use



fNamef = fName1 & "_" & Format(Now, "mmm-dd-yyyy hh-mm-ss") & ".ppsm"

JimS
04-26-2011, 12:30 PM
Now it fails on the word "Format".

Bob Phillips
04-26-2011, 12:49 PM
In the VBIDE, go to Tools>References. If there is a MISSING item, uncheck it.

JimS
04-26-2011, 01:00 PM
That did it - THANKS...

Not sure how the particualr missing item was affecting this part of the code, but it's fixed is all I care about (for now)...

Thanks again...

Bob Phillips
04-26-2011, 01:07 PM
It's a bug/feature, VBA handles it incorrectly.