How to refresh daily data with additional text included in date filename

chachie

New Member
Joined
Nov 21, 2006
Messages
10
Hello,

We have a number of CSV files which are created daily by our modelling software. I would like to import the most recent csv data into their respective excel sheets. Each csv file is saved in a single folder generated by the model. An example of the saved csv file are saved like this:

C:\HGSensembleForecast\Module\postprocess\20190829UTC12\W0000097_HGA_A_HGS.csv

Note the folder with the date 2019 08 29 includes the text UTC12. Is there a way for excel to ignore the UTC12 text and copy the data from the csv file saved in the folder with the most recent date? The only thing that changes in the location path is the date stamp. The csv filename is always the same.

Thanks
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this

Code:
Sub refresh_daily_data()
  Dim wPath As String, wDate As String, wFile As String, wb As Workbook
  
  wPath = "C:\HGSensembleForecast\Module\postprocess\"
  wPath = "C:\trabajo\books\"
  wDate = Format(Date, "yyyymmdd") & "UTC12\"
  wFile = "W0000097_HGA_A_HGS.csv"
  
  Set wb = Workbooks.Open(wPath & wDate & wFile)
  wb.Sheets(1).Copy after:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
  wb.Close
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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