referencing folder named *current year*

npacker

Board Regular
Joined
Oct 14, 2004
Messages
132
I'm running a macro on an excel template that does a "save as" on open and I would like it to save to a certain location. However, depending on what year it is, it will save to a different folder. In the location where I want to save it, there are folders named after the year, ie, "2004", "2005", "2006", etc...

I set up a variable called FName, whick defines the location I want it to save to, and then set it equal to
Code:
FName = "U:\First Folder\Second Folder\" & ActiveWorkbook.Name

After the second folder, I would like it to check the date, and if it is 2005, I would then like it to go from the second folder, to the folder named 2005, or if is 2006, then to that folder.

Can I set up a variable that is equal to the current year in the 4-digit format, and then call that variable in the folder location?

Any help would be appreciated.
Thanks,
Nate
 
That was totally my problem. I was looking for a text file, but the file is ACTUALLY an excel spreadsheet. So I changed the code to be Workbooks.OPen Filename...
So it works now, but I have one more question.
The path it needs to go to is U:\DFAS OST\Turnover\*current year*\*current month*\ and then look in the *current month* folder for the file. However, I have a variable set up called CurrMonth, and it equals Month(Date). The Month(Date) format is set to be a "1" for January, "2" for February, and so forth. But the folder is actually called "January." Can I change the format to look for "January", rather than "1"
Thanks so much for all your help thus far!
Nate
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Sure, just use the MonthName command instead.

Using:
CurrMonth=MonthName(Month(Date))

Should return "January"

Using:
CurrMonth=MonthName(Month(Date),True)

Should return "Jan"
 
Upvote 0
Thanks, that's perfect. You've been most helpful. What do you do for a living? You're a pro at this!
Nate
 
Upvote 0
The code is working now, but if the new file has already been created, of course Excel comes up and says, "This file already exists, would you like to replace it?" If you click yes, that's fine, it replaces it, but if you click no, the code errors, cause the SaveAs failed. Is there any way, I can tell the code that if the user answers "No", then to go to the end of the sub or something?
Thanks,
Nate
 
Upvote 0

Forum statistics

Threads
1,215,670
Messages
6,126,127
Members
449,293
Latest member
yallaire64

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