Consulting

Results 1 to 3 of 3

Thread: VBA is looping, not sure why

  1. #1
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    2
    Location

    Question VBA is looping, not sure why

    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
    Last edited by SamT; 06-14-2017 at 01:07 PM. Reason: Added Line Continuation marks, Line breaks, and white space for readability

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Newbie
    Joined
    Jun 2017
    Posts
    2
    Location
    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •