I have tried below VBA code to close the inactive workbook but it is not working.
Workbooks(VBA.Environ("Username") & ".xls").Close True
Workbooks(“p468904.xls").Close SaveChanges:=True
Workbooks.Close Filename:=VBA.Environ("Username") & ".xls"
Workbooks(VBA.Environ("Username") & ".xls").Close SaveChanges:=True
If you want to close all workbooks except the one the code is in,
For Each wkb In Workbooks
If Not wkb Is ThisWorkbook Then wkb.Close SaveChanges:=False ' or True, depending
Next wkb
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.