VBA to select Save As Folder

craigg3

Board Regular
Joined
Dec 23, 2002
Messages
161
Office Version
  1. 2013
Platform
  1. Windows
I have a button that users can click which will open the SaveAs popup box, where the user can input a file name to save as. What I need it to also do is to go to a particular folder to save into. The folder (called "Cost") is in the same folder as the excel spreadsheet, but need to keep them separate than the master file so I create the folder "Cost" to save to. The user will still need to be able to name the file during the SaveAs popup, I just need the SaveAs popup to default to the "Cost" folder. Not sure how to make it default to the "Cost" folder while still allowing the user to name the file whatever they need to. Any help would be appreciated. Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
How are you popping up the SaveAs dialog?
 
Upvote 0
You can use the InitialFileName argument of Application.GetSAveAsName to specify the starting folder.
Code:
Dim strFileName As String
Dim strPath As String

    strPath = ThisWorkbook.Path & "\Cost\"

    strFileName = Application.GetSaveAsFilename(InitalFileName:=strPath)
 
Upvote 0
You can use the InitialFileName argument of Application.GetSAveAsName to specify the starting folder.
Code:
Dim strFileName As String
Dim strPath As String

    strPath = ThisWorkbook.Path & "\Cost\"

    strFileName = Application.GetSaveAsFilename(InitalFileName:=strPath)

Norie,
Thanks for the help. When trying the code, it does pop up to the correct folder, but when I type a file name into the dialog box and click save, it seems like it works, but then it doesn't save anything. Any idea why? Thanks.
 
Upvote 0
GetSaveAsFilename doesn't actually save anything, all it does is get the filename to use when saving.

So you'll need to add your own code to do the actual saving using the filename the user entered.
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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