PPT "Save As" dialog box from VBA-VBForums
Results 1 to 7 of 7

Thread: PPT "Save As" dialog box from VBA

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2007
    Posts
    86

    PPT "Save As" dialog box from VBA

    so i have this code but it only 'shows' the dialog box.
    it does not save or rather it saves as the default name, like "Presentation2"

    Dim dlgSaveAs As FileDialog
    Set dlgSaveAs = Application.FileDialog( _
    Type:=msoFileDialogSaveAs)
    dlgSaveAs.Show

    In Excel I can pick up the name the user saves e.g.

    strMyFile = Application .GetSaveAsFinename(fileFilter:="Excel files(*.xls),*.xls")

    The program opens a new presentation and I would like the user to be able to save it themselves. Right now I have it saved with a user entered date and location.

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: PPT "Save As" dialog box from VBA

    You are nearly there, but you need to check the return of dlgSaveAs.Show, that wil be -1 (a filename selected) or 0 (cancel).
    Then get the filename from dlgSaveAs.SelectedItems(1)

    Code:
        Dim dlgSaveAs As FileDialog
        Dim strMyFile As String
        
        Set dlgSaveAs = Application.FileDialog(fileDialogType:=msoFileDialogSaveAs)
        With dlgSaveAs
            .InitialFileName = "Presentation2_" & Format(Date, "yyyy-mm-dd")
            If .Show = -1 Then
                strMyFile = .SelectedItems(1)
                MsgBox strMyFile
                '-- save your file to strMyFile here
            'Else
                '-- The user pressed Cancel.
            End If
        End With
        Set dlgSaveAs = Nothing
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    Baby Steps a guided tour
    IsDigits() and IsNumber() functions Wichmann-Hill Random() function >> and << functions for VB CopyFileByChunk

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    25

    Re: PPT "Save As" dialog box from VBA

    I tried the code above in Powerpoint 2007, but I don't see any dialog at all?

    Any help?

  4. #4
    Addicted Member
    Join Date
    Jan 2009
    Posts
    182

    Re: PPT "Save As" dialog box from VBA

    I think he used code for the FileDialog for a different office application. Just reset to what you were using in your origina(Type:=msoFileDialogSaveAs)l:
    Code:
        Dim dlgSaveAs As FileDialog
        Dim strMyFile As String
        
        Set dlgSaveAs = Application.FileDialog(Type:=msoFileDialogSaveAs)
        With dlgSaveAs
            .InitialFileName = "Presentation2_" & Format(Date, "yyyy-mm-dd")
            If .Show = -1 Then
                strMyFile = .SelectedItems(1)
                MsgBox strMyFile
                '-- save your file to strMyFile here
            'Else
                 MsgBox "No file selected."
               '-- The user pressed Cancel.
            End If
        End With
        Set dlgSaveAs = Nothing

  5. #5
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,928

    Re: PPT "Save As" dialog box from VBA

    In the above code chnage

    Set dlgSaveAs = Application.FileDialog(fileDialogType:=msoFileDialogSaveAs)
    to

    Code:
    Set dlgSaveAs = Application.FileDialog(Type:=msoFileDialogSaveAs)
    Also do you have this line

    Code:
    On Error Resume Next
    Anywhere? If yes, then remove it...

    Edit:
    Holy Cow, I didn't refresh the screen!!! mark beat me to it
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: PPT "Save As" dialog box from VBA

    FileDialog() has only one parameter. This parameter name may be different between Office applications and versions (annoyed!).
    You can omit this name and also the constant msoFileDialogSaveAs = 2
    Code:
    Sub SaveMeAs()
        Dim dlgSaveAs As FileDialog
        
        Set dlgSaveAs = Application.FileDialog(2)
        With dlgSaveAs
            .InitialFileName = "Presentation2_" & Format(Date, "yyyy-mm-dd")
            If .Show = -1 Then
                Application.ActivePresentation.SaveAs .SelectedItems(1)
            End If
        End With
        Set dlgSaveAs = Nothing
    End Sub
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    Baby Steps a guided tour
    IsDigits() and IsNumber() functions Wichmann-Hill Random() function >> and << functions for VB CopyFileByChunk

  7. #7
    Junior Member
    Join Date
    Oct 2009
    Posts
    25

    Re: PPT "Save As" dialog box from VBA

    thx guys, I used the following code now:

    Code:
    Sub SaveAsButton()
        Dim dlgSaveAs As FileDialog
        Dim strMyFile As String
        
        Set dlgSaveAs = Application.FileDialog(Type:=msoFileDialogSaveAs)
        With dlgSaveAs
            .InitialFileName = ActivePresentation.Name
            If .Show = -1 Then
                strMyFile = .SelectedItems(1)
                ActivePresentation.SaveAs (strMyFile)
                MsgBox "File was saved."
                '-- save your file to strMyFile here
            Else
                 MsgBox "File was not saved."
               '-- The user pressed Cancel.
            End If
        End With
        Set dlgSaveAs = Nothing
    End Sub
    This works fine in a seperate powerpoint, however when I enter the powerpoint from another powerpoint (in kiosk mode), then I get the saveas diolog, but it does not continue and save the ppt ...

    any suggestions for that?

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.