sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
When I try the code below, I get a "Compile error: Wrong number of arguments or invalid property assignment" error. The ".close" part of the code is what is highlighted when I select "OK" to close the error message. I'm having a tough time seeing what would cause this. I just want the files below (all opened as "Read Only") to close when I exit my workbook. They are opened in the background because I have a lot of XLOOKUP formulas that point to them and I can only see those results when they are opened. Any help on this would be much appreciated. Thanks, SS
VBA Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim my_wb1 As Workbook
Dim my_wb2 As Workbook
Dim my_wb3 As Workbook
Dim my_wb4 As Workbook
Dim file_path1 As String
Dim file_path2 As String
Dim file_path3 As String
Dim file_path4 As String
file_path1 = "H:\Jobs\PO Block History.xlsm"
file_path2 = "G:\Manufacturing\Manufacturing Detail Schedule1.xlsx"
file_path3 = "H:\Shop Files\MRL Production Schedule\Production Schedule.xlsm"
file_path4 = "H:\Jobs\00 ENGINEERING DATA\Job List.xlsm"
Set my_wb1 = Workbooks.Close(Filename:=file_path1, SaveChanges:=False)
Set my_wb2 = Workbooks.Close(Filename:=file_path2, SaveChanges:=False)
Set my_wb3 = Workbooks.Close(Filename:=file_path3, SaveChanges:=False)
Set my_wb4 = Workbooks.Close(Filename:=file_path4, SaveChanges:=False)
End Sub