Consulting

Results 1 to 5 of 5

Thread: msoFileDialogSaveAs - no error on file save when file is open

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location

    msoFileDialogSaveAs - no error on file save when file is open

    Hello,
    I'm not sure what I'm doing wrong. I get no error notification when I try to overwrite the file which is open in different app. For example Acrobat.
    Like the error is not triggered.

    code.jpg



    Thank you in advance

  2. #2
    VBAX Mentor
    Joined
    Nov 2022
    Location
    The Great Land
    Posts
    331
    Location
    Should post code as text between CODE tags so readers can copy/paste it - not image. Can edit your post.

    Have you step debugged?
    How to attach file: Reading and Posting Messages (vbaexpress.com), click Go Advanced below post edit window. To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    Quote Originally Posted by June7 View Post
    Should post code as text between CODE tags so readers can copy/paste it - not image. Can edit your post.

    Have you step debugged?
    Hi, you are right. Sorry. Pasted an image.

    I have added
    Application.DisplayAlerts = True
    Now it asks if I'm sure that I want to overwrite the file but there is no warning box that it could not be done as file is currently in use.

    Tbh I can use native
    Application.CommandBars.ExecuteMso("FileSaveAs")
    but I would like to have more custom dialog

    Here is what I have now:

    Sub CommandButton3_Click()
    
    Dim dlgSaveAs As FileDialog
    
    On Error GoTo ErrorHandler
    Application.DisplayAlerts = True
    
    If Application.Presentations.Count = 0 Then
    Call MsgBox("Please open presentation file before save", vbExclamation, "Test")
    Exit Sub
    End If
    
    Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
    
    dlgSaveAs.Title = "Save PDF"
    dlgSaveAs.ButtonName = "Save PDF"
    dlgSaveAs.FilterIndex = 4
    
    With dlgSaveAs
        If .Show Then
            .Execute
            Call MsgBox("PDF was saved successfully", vbInformation, "Test")
        Else
            Call MsgBox("PDF was not saved", vbInformation, "Test")
        End If
    End With
    
    NormalExit:
        Exit Sub
    
    ErrorHandler:
         MsgBox "Error"
         Resume NormalExit:
    
    End Sub

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Try

    Sub test()
    Dim dlgSaveAs As FileDialog
    Dim strPath As String
    On Error GoTo ErrorHandler
    If Application.Presentations.Count = 0 Then
       Call MsgBox("Please open presentation file before save", vbExclamation, "Test")
       Exit Sub
    End If
    Set dlgSaveAs = Application.FileDialog(msoFileDialogSaveAs)
    dlgSaveAs.Title = "Save PDF"
    dlgSaveAs.ButtonName = "Save PDF"
    dlgSaveAs.FilterIndex = 4
    With dlgSaveAs
        If .Show Then
            call  ActivePresentation.SaveAs (.SelectedItems(1), ppSaveAsPDF)
            Call MsgBox("PDF was saved successfully", vbInformation, "Test")
        Else
            Call MsgBox("PDF was not saved", vbInformation, "Test")
        End If
    End With
    NormalExit:
        Exit Sub
    ErrorHandler:
         MsgBox "Error"
         Resume NormalExit
    End Sub
    Last edited by John Wilson; 12-20-2022 at 08:31 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  5. #5
    VBAX Regular
    Joined
    May 2017
    Posts
    18
    Location
    Thank you!
    I had a feeling this .Excecute was a problem.
    I added path checking in ErrorHandler MsgBox so now it reflects native SaveAs behaviour.

Posting Permissions

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