Hello
I tried to close a file in a folder. Part of folder path is named using cell ranges in another worksheet. It keeps on giving me an error message 'run-time error 9, script out of range'.
My code runs fine, until the last line which is to close a specific file (bolded line below):
codes are long, so I pasted only the relevant codes here. Any idea on what should be changed?
sub macro2()
dim fcurrentyear As String
dim fyyyymmdd As String
dim fdate = InputBox("Enter YYYYMMDD")
dim fdate1 = fdate & "data.xlsm"
fcurrentyear = Workbooks("total.xlsm").Worksheets("Main").Range("j2")
fyyyymmdd= Workbooks("total.xlsm").Worksheets("Main").Range("j2")
'''open some files here'''
Workbooks("P:\users\" & fcurrentyear & "" & fyyyymmdd & "" & "test" & "" & fyyyymmdd & "_data.xlsm". Close savechanges:=false
end sub()
I tried to close a file in a folder. Part of folder path is named using cell ranges in another worksheet. It keeps on giving me an error message 'run-time error 9, script out of range'.
My code runs fine, until the last line which is to close a specific file (bolded line below):
codes are long, so I pasted only the relevant codes here. Any idea on what should be changed?
sub macro2()
dim fcurrentyear As String
dim fyyyymmdd As String
dim fdate = InputBox("Enter YYYYMMDD")
dim fdate1 = fdate & "data.xlsm"
fcurrentyear = Workbooks("total.xlsm").Worksheets("Main").Range("j2")
fyyyymmdd= Workbooks("total.xlsm").Worksheets("Main").Range("j2")
'''open some files here'''
Workbooks("P:\users\" & fcurrentyear & "" & fyyyymmdd & "" & "test" & "" & fyyyymmdd & "_data.xlsm". Close savechanges:=false
end sub()