Link to home
Start Free TrialLog in
Avatar of Rick Danger
Rick DangerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Can I specify a file to save using FileDialog SaveAs Code?

I want to allow my user to save a file using Office.FileDialog. Is it possible? I need to be able to specify the filename and initial directory
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Yes, using the InitialFileName property, for example Application.FileDialog.InitialFileName  = "c:\MyText.txt"
Avatar of Rick Danger

ASKER

But that's not telling me how to save the file. This is my code:

   Dim strFolderPath As String
   Dim fd As Office.FileDialog
   Dim strPath As String
 
   'Create a FileDialog object as a Folder Picker dialog box.
   Set fd = Application.FileDialog(msoFileDialogFilePicker)
 
   'Set strPath to the folder you want to open initially
   strPath = "C:\Dropbox\"
    With fd
        .Filters.Clear
        .Filters.Add "PDF Documents", "*.pdf"
        .Title = "Browse for folder where you would like to save the PDF"
        .ButtonName = "Save"
        .InitialFileName = strPath
        .InitialView = msoFileDialogViewDetails
        If .Show = -1 Then
            strFolderPath = CStr(fd.SelectedItems.Item(1)) & "\"
        Else
            MsgBox "You chose cancel"
            strFolderPath = ""
        End If
   End With
 
   SelectFolder = strFolderPath

So how do I change it to save a file please
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial