Hi everyone,
I am a newbie in VBA, hence seeking your help with the following code:
The code copies data from a closed source workbook location of which is defined as "H:\documents\file_2020-07-13_2020-07-14_000501UTC.csv". The name of the file which contains the source data contains the date, how would you set the name dynamic e.g. "H:\documents\file_[yesterday in format above]_[today in format above]_000501UTC.csv]?
Each day, I will be downloading a new source file with a name generated in a format above.
Thanks for your advice.
I am a newbie in VBA, hence seeking your help with the following code:
VBA Code:
Sub copyColData()
' copy data from closed workbook
Dim lastRow As Long
Dim myApp As Excel.Application
Dim wkBk As Workbook
Dim wkSht As Object
Set myApp = CreateObject("Excel.Application")
Set wkBk = myApp.Workbooks.Open("H:\documents\file_2020-07-13_2020-07-14_000501UTC.csv")
lastRow = wkBk.Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
wkBk.Sheets(1).Range("C2:H" & lastRow).Copy
myApp.DisplayAlerts = False
wkBk.Close
myApp.Quit
Set wkBk = Nothing
Set myApp = Nothing
Set wkBk = ActiveWorkbook
Set wkSht = wkBk.Sheets("Sheet1")
wkSht.Activate
Range("A1").Select
wkSht.Paste
' delete columns with unnecesary data
Range("B:B,D:D").Delete
Exit Sub
End Sub
The code copies data from a closed source workbook location of which is defined as "H:\documents\file_2020-07-13_2020-07-14_000501UTC.csv". The name of the file which contains the source data contains the date, how would you set the name dynamic e.g. "H:\documents\file_[yesterday in format above]_[today in format above]_000501UTC.csv]?
Each day, I will be downloading a new source file with a name generated in a format above.
Thanks for your advice.