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
    183

    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
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  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
  •  



Click Here to Expand Forum to Full Width