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.
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
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? :)
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
Re: PPT "Save As" dialog box from VBA
In the above code chnage
Quote:
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 :lol:
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
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?