Hello,
I am trying to create a vba that will allow a user to enter his chosen date in the dialog box (eg. 20160730), then open a file from the previous month of his chosen date, as there is only 1 file per month in the folder (eg. 20160630_country.xlsm), and rename this file using the user's chosen date YYYYMMDD entered in the dialog box (20160730_country_xlsm). I've managed to get most done, except the part that should identify the file from the previous month. Any idea?
Dim fname As String
Dim fpath As String
fname1 = InputBox("enter date YYYYMMDD")
fname = fname1 & "_country.xlsm"
fpath = "C:\Users\Desktop"
Workbooks.Open Filename:= _
C:\Users\kc\Desktop\folder" & fname1 - 1 & "_data.xlsx" <---error here
ActiveWorkbook.SaveAs Filename:=fpath & fname, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
I am trying to create a vba that will allow a user to enter his chosen date in the dialog box (eg. 20160730), then open a file from the previous month of his chosen date, as there is only 1 file per month in the folder (eg. 20160630_country.xlsm), and rename this file using the user's chosen date YYYYMMDD entered in the dialog box (20160730_country_xlsm). I've managed to get most done, except the part that should identify the file from the previous month. Any idea?
Dim fname As String
Dim fpath As String
fname1 = InputBox("enter date YYYYMMDD")
fname = fname1 & "_country.xlsm"
fpath = "C:\Users\Desktop"
Workbooks.Open Filename:= _
C:\Users\kc\Desktop\folder" & fname1 - 1 & "_data.xlsx" <---error here
ActiveWorkbook.SaveAs Filename:=fpath & fname, _
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False