-
May 8th, 2008, 07:46 AM
#1
Thread Starter
Lively Member
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.
-
May 11th, 2008, 09:14 PM
#2
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
-
Feb 26th, 2010, 11:07 AM
#3
Junior Member
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?
-
Feb 26th, 2010, 11:35 AM
#4
Addicted Member
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
-
Feb 26th, 2010, 11:41 AM
#5
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
-
Feb 26th, 2010, 06:57 PM
#6
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
-
Mar 3rd, 2010, 05:25 AM
#7
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|