Can anybody please help with this error in my code
I have set up opening a source workbook using the Workbook_Open event, which works just great.
I need to then close the source workbook using the BeforeClose event without saving any changes. But I keep getting “Object required” error
Any help is appreciated code below
I have set up opening a source workbook using the Workbook_Open event, which works just great.
I need to then close the source workbook using the BeforeClose event without saving any changes. But I keep getting “Object required” error
Any help is appreciated code below
VBA Code:
Private Sub Workbook_Open()
Dim WB As Workbook
Dim CurrentSheet As Worksheet
Set CurrentSheet = ActiveSheet
Set Wkbk = ActiveWorkbook
Application.ScreenUpdating = False ' turn off the screen updating
Sheets("Running List").Select
Set WB = Workbooks.Open("C:\Users\Gary Baker\Documents\Lion Engineering\W4G\W4G\Operational Data\_Databases\Customer List.xlsx", True, True)
Application.ScreenUpdating = True ' turn on the screen updating
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim WB As Workbook
Dim CurrentSheet As Worksheet
Set CurrentSheet = ActiveSheet
Set Wkbk = ActiveWorkbook
Set WB = Workbook
Application.ScreenUpdating = False ' turn off the screen updating
WB.Close savechanges:=False ' close the source workbook without saving any changes
Wkbk.Activate
Application.ScreenUpdating = True ' turn on the screen updating
End Sub