PDA

View Full Version : VBA is looping, not sure why



miyo
06-14-2017, 03:04 AM
Hi,

I created a PowerPoint add-in with the code below and this was working well for months. For some reason (perhaps a Windows/Office update?) this no longer works. When I step through the code, it loops at "Exit Sub" back to the beginning. Can anyone suggest what might have broken?


Sub SaveAsPDF()
If ActivePresentation.Saved = msoFalse Then _
MsgBox "Please save your Presentation first"
Exit Sub

Dim FinalFileName As String
FinalFileName = Left(ActivePresentation.Name, _
(InStrRev(ActivePresentation.Name, ".", -1)))

ActivePresentation.ExportAsFixedFormat ActivePresentation.Path _
& "\" & FinalFileName _
& "pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint, , , , , , , , , , _
DocStructureTags:=False

MsgBox "Document saved to " & ActivePresentation.Path _
& "\" & FinalFileName & "pdf"

End Sub

Thanks in advance
miyo

Paul_Hossler
06-14-2017, 11:38 AM
Seems OK for me

BTW, are you sure that your macro was what you intended?

If the presentation WAS NOT saved, you get the message and then exit the sub
If the presentation WAS saved, you exit the sub






Option Explicit
Sub SaveAsPDF()
Dim FinalFileName As String

If ActivePresentation.Saved = msoFalse Then
MsgBox "Please save your Presentation first"
Exit Sub
End If

FinalFileName = Left(ActivePresentation.Name, (InStrRev(ActivePresentation.Name, ".", -1)))
ActivePresentation.ExportAsFixedFormat ActivePresentation.Path & "\" & FinalFileName & "pdf", ppFixedFormatTypePDF, ppFixedFormatIntentPrint, , , , , , , , , , DocStructureTags:=False

MsgBox "Document saved to " & ActivePresentation.Path & "\" & FinalFileName & "pdf"
End Sub

miyo
06-15-2017, 12:21 AM
Hi Paul.

Thanks for replying. It seems I was missing the 'End If' from line 8. Newbie error! I have tried your tidier code and it works fine so thanks very much!

The intention of the macro is to save the current presentation as PDF, but with the "Doc Structure Tags" removed (set to 'false' in this case).

The macro should first check if the presentation is saved. If not, it prompts the user. If it is saved, then it continues to save as PDF (using the current file name and path) with the save options mentioned above. It then shows a message to the user that this has been done.

Many thanks!