Can i refer to a sheet's code name when using VBA to import into another file? The tab names could be changed so I want to use something static. The index could change as well if the order of the tabs in the other file is changed.
Here's my code to import:
Sub OpenFORECASTfile()
'OPENS PRIOR YEAR REFORECAST FILE
On Error GoTo ErrorHandler
Dim myFile2 As Variant, wbkFOR As Workbook
myFile2 = Application.GetOpenFilename("All Files,*.*")
Application.DisplayAlerts = False
Set wbkFOR = wbkFOR
Application.DisplayAlerts = True
Set wbkFOR = Workbooks.Open(Filename:=myFile2)
Application.EnableEvents = False
'GO GETS REFORECAST DATA
'On Error GoTo ErrorHandler
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ThisWorkbook.Sheets("RFUPLOAD").Activate
Module1.UnProtectIt
'COPY/PASTE DATA INTO NEW FILE
'Golf
wbkFOR.Sheet23.Range("B1:BJ225").Copy
ThisWorkbook.Sheets("RFUPLOAD").Range("B7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
It gets hung up on wbkFOR.Sheet23.Range("B1:BJ225").Copy. The error says "Object doesn't support this property or method."
Thanks!
Here's my code to import:
Sub OpenFORECASTfile()
'OPENS PRIOR YEAR REFORECAST FILE
On Error GoTo ErrorHandler
Dim myFile2 As Variant, wbkFOR As Workbook
myFile2 = Application.GetOpenFilename("All Files,*.*")
Application.DisplayAlerts = False
Set wbkFOR = wbkFOR
Application.DisplayAlerts = True
Set wbkFOR = Workbooks.Open(Filename:=myFile2)
Application.EnableEvents = False
'GO GETS REFORECAST DATA
'On Error GoTo ErrorHandler
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
ThisWorkbook.Sheets("RFUPLOAD").Activate
Module1.UnProtectIt
'COPY/PASTE DATA INTO NEW FILE
'Golf
wbkFOR.Sheet23.Range("B1:BJ225").Copy
ThisWorkbook.Sheets("RFUPLOAD").Range("B7").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
It gets hung up on wbkFOR.Sheet23.Range("B1:BJ225").Copy. The error says "Object doesn't support this property or method."
Thanks!