PDA

View Full Version : [SOLVED:] save a file using vba and the file dialog



hilyete
05-17-2017, 09:34 AM
I'm trying to put in code to save the active presentation using the file dialog box. I can get the dialog box to appear with this:


Application.FileDialog(msoFileDialogSaveAs).Title = _
"Random Title For Dialog"
'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogSaveAs).Show
'determine what choice the user made
If intChoice <> 0 Then
'your code here"
End If
End Sub


But I don't understand what I need to change so that the file name I type in the dialog box is saved. The "intChoice" variable above doesn't seem to do anything, whether I select a file, or type a new name in. What code do I need in the "your code here" part of this routine? I tried "activepresentation.save", and it did, but saved the file as "-1" and not with the name I typed in the dialog box.

Thanks for anyone's help.

Paul_Hossler
05-17-2017, 03:13 PM
Googling for msoFileDialogSaveAs finds lots of examples

http://software-solutions-online.com/vba-save-file-dialog-filedialogmsofiledialogsaveas/





Sub Example1()
Dim intChoice As Integer
Dim strPath As String

'make the file dialog visible to the user
intChoice = Application.FileDialog(msoFileDialogSaveAs).Show

'determine what choice the user made
If intChoice <> 0 Then

'get the file path selected by the user
strPath = Application.FileDialog(msoFileDialogSaveAs).SelectedItems(1)

'displays the result in a message box
Call MsgBox(strPath, vbInformation, "Save Path")

End If
End Sub

hilyete
05-17-2017, 03:27 PM
Thanks Paul... works great!

Paul_Hossler
05-17-2017, 07:22 PM
Glad

You can mark this [Solved] by going to [Thread Tools] above your first post and clicking the radio button