Open csv file that has current date in the name VBA code

SantanaKRE8s

Board Regular
Joined
Jul 11, 2023
Messages
131
Office Version
  1. 365
Platform
  1. Windows
Hello can someone help, I am trying to automatically open a csv file that has current date on the name so I can transfer certain columns into my workbook. Below is the VBA code I have. I get error that the file could have been moved or deleted. I placed VBA code in Module 1

Sub OpenCSV()

Workbooks.Open "C:\Users\Bsantana\OneDrive - TTI, Inc\SPACEX\BACKLOGREPORT\OPEN ORDER REPORTS_SPX\SpaceX_Open_Order_Report_" & Format(Date, "mm-dd-yyyy") & ".csv"

End Sub


1696372101207.png
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Actually, just realized that we probably have to do the same thing for the month. For example, if the date for your January file is formatted as "1-31-2023", then it should be...

VBA Code:
format(Date, "m-d-yyyy")
 
Upvote 0
when the date no longer has a 0 opn the day but it becomes 11 or 22, will it still open?
Yes, it will return the day without a leading zero. So a single digit will be returned for a single digit day and a double digit will be returned for a double digit day. The last one I posted will return both the month and day without the leading zero. So same thing here.
 
Upvote 0
Arg! You would not believe how many times I looked at that over and over again, and missed that leading zero on the day!
Thanks for the assist and third set of eyes!
Easy to overlook, I've done it myself as well... :-)
 
Upvote 0
Thank you both, its working, question, Im doing the same for an XLSX file and Im back to same error. Ive tried the same fix but not working

Sub vba_open_workbook()

Workbooks.Open "C:\Users\Bsantana\OneDrive - TTI, Inc\SPACEX\BACKLOGREPORT\LIST REPORTS_ TTI\WAS_CAS_" & Format(Date, "mm-d-yyyy") & ".xlsx"

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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