Amend code to save to a sub-folder

Mel Smith

Well-known Member
Joined
Dec 13, 2005
Messages
1,023
Office Version
  1. 365
Platform
  1. Windows
I'm trying to use VBA to save files to sub-folders. The line of code that I'm using is:

Path = "C:\Users\melsm\Desktop\Averages\CC"

however, the files are saved in the Averages folder and not the sub-folder I want. Is there something wrong with my code?

The next two lines of code are:

filename = Range("B1")
ActiveSheet.SaveAs filename:=Path & filename & " " & Format(Date, "dd-mmm") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook

Thank you.

Mel
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Could you please try:
VBA Code:
ActiveSheet.SaveAs filename:=Path & "\" & filename & " " & Format(Date, "dd-mmm") & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
Or you may add a back-slash at the end of your path..
 
Upvote 0
Solution
It was the back slash that I'd missed. Adding it did the trick.

Many thanks, Flashbond.

Mel
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,720
Members
448,986
Latest member
andreguerra

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