How can I amend this code to save WB in specific folder?

storemannequin

Board Regular
Joined
May 29, 2010
Messages
108
So I'm trying to understand how to save a workbook in a specific folder. Let's us 'C:\my documents' for instance as the directory. Can anyone help amend this bit to reflect this change? 'WBD' is the workbook I'm trying to save and 'mydocspath' is the file path to save to.

Code:
MyDocsPath = Environ$("USERPROFILE") & "\My Documents\"
 
FN = "ThisWB" & " For " & MonthName(Month(Date) - 1) & "_" & Year(Now) & ".xlsx"
FP = MyDocsPath.Path & Application.PathSeparator
 
    WBD.SaveAs Filename:=FP & FN
    WBD.Close savechanges:=False
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I'm getting an error that the file path doesn't exist:

Code:
 FN = "ThisWB" & " For " & MonthName(Month(Date) - 1) & "_" & Year(Now) & ".xlsx"
    FP = "C:\My Documents" & Application.PathSeparator
    
    ActiveWorkbook.SaveAs Filename:=FP & FN
    'WBD.Close savechanges:=False
 
Upvote 0
Normally the path to My Documents would be something like

C:\Users\username\my documents
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

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