VBA - Opening files with odd date formats

ukanez

New Member
Joined
Dec 7, 2017
Messages
21
I need to access a file made monthly that gets spit out in a weird date format. The files are named source1901.xls (19 for year 01 for month), source1902.xls (02 for February etc).

Code:
Workbooks.Open Filename:="L:\sales\output\source" & Format(DateAdd("m", -1, Date), "YYMM") & ".xls", UpdateLinks:=False

I don't have problems with files that are formatted properly as I just use the "MMMM YYYY" designation for those but I can't seem to figure out how to get it to translate the year and month into two digits (19 for 2019 and 01 for January for example. So 1901).

Thanks for the help!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
When I changed the path and file extention to my user folder your code opened a file named source1902.xlsx. Check that the path and extension is correct
 
Upvote 0

Forum statistics

Threads
1,203,171
Messages
6,053,885
Members
444,692
Latest member
Queendom

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