File save prompt for location

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
Office Version
  1. 365
Hi,

I have tried to modify the code below to select the folder to save at but not luck, how to modify it to prompt for saving location and start at this location:

C:\Users\jose.rossi\Desktop\Excel Files\Reconciliations\

code:

VBA Code:
Sub PDFActiveSheet()
'Varriables
Dim SaveRng As Range
Dim pdfname As String
Dim path As String


'Setting range to be saved
Set SaveRng = Range("SAVE_PDF")

'setting file name with a cell value
CurrentMonth = Format(ActiveSheet.Range("E1").Value, "mm-dd-yyyy")
pdfname = Range("V2") & "_" & CurrentMonth

'path
path = "C:\Users\jose.rossi\Desktop\Excel Files\Reconciliations\"

'save the range as pdf
SaveRng.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=path & pdfname & ".pdf"


End Sub

Thank you,
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try replacing...

Code:
path = "C:\Users\jose.rossi\Desktop\Excel Files\Reconciliations\"

with

VBA Code:
    With Application.FileDialog(msoFileDialogFolderPicker)
        .ButtonName = "Select"
        .InitialFileName = "C:\Users\jose.rossi\Desktop\Excel Files\Reconciliations\"
        .Title = "Select Folder"
        If .Show = 0 Then Exit Sub
        path = .SelectedItems(1) & "\"
    End With

Actually, I would suggest placing the above code at the beginning of your macro. This way, if the user cancels the file dialog box, the code can exit the sub without executing any other lines of code.

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top