obriensj
12-16-2008, 06:52 AM
Hi,
Hoping someone can help!?
I need to be able to write a macro which will open up numerous csv files stored in a folder. The thing being that i need the macro to read the file name and pick up yesterday's date.
For example the file name could be called:
ivp432_system_08-12-15_21e93280.csv
ivp432_system_08-12-15_21eb9261.csv
ivp432_system_08-12-15_21ea0238.csv
There are upto 40 or so different file names the only consistent thing being the start of the file name: ivp432_system_
I need a bit of code which will open up all these files (40 or so) when the date is yesterday's date, ie 08-12-15 in the file name. Also on a Monday i need the macro to work back 3 days, so on Monday 08-12-22 i need it to be able to pick up files with the date 08-12-19 in the file name.
I had an old bit of code below which i thought could help me so tried to amend but no luck.
Can anyone help?
Thanks
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object
Application.DisplayAlerts = False
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("\\C\test (file://\\C\test)Macros\")
For Each file In Folder.Files
If file.Type Like "*Comma Separated*" Then
If file.Name Like "*Ivp432_system" & Format(Date - 1, "yy-mm-dd") & "*" Then
Workbooks.Open Filename:=file.Path
'process it
Hoping someone can help!?
I need to be able to write a macro which will open up numerous csv files stored in a folder. The thing being that i need the macro to read the file name and pick up yesterday's date.
For example the file name could be called:
ivp432_system_08-12-15_21e93280.csv
ivp432_system_08-12-15_21eb9261.csv
ivp432_system_08-12-15_21ea0238.csv
There are upto 40 or so different file names the only consistent thing being the start of the file name: ivp432_system_
I need a bit of code which will open up all these files (40 or so) when the date is yesterday's date, ie 08-12-15 in the file name. Also on a Monday i need the macro to work back 3 days, so on Monday 08-12-22 i need it to be able to pick up files with the date 08-12-19 in the file name.
I had an old bit of code below which i thought could help me so tried to amend but no luck.
Can anyone help?
Thanks
Dim oFSO As Object
Dim Folder As Object
Dim Files As Object
Dim file As Object
Application.DisplayAlerts = False
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set Folder = oFSO.GetFolder("\\C\test (file://\\C\test)Macros\")
For Each file In Folder.Files
If file.Type Like "*Comma Separated*" Then
If file.Name Like "*Ivp432_system" & Format(Date - 1, "yy-mm-dd") & "*" Then
Workbooks.Open Filename:=file.Path
'process it