下面的供参考。注意增加的宏需要放在VBA Workbook的里面。 Private Sub Workbook_Open() Dim Wb As Workbook For Each Wb In Workbooks If Wb.Name <> ThisWorkbook.Name Then Wb.Close '如果要强行不保存关闭,可以加上 savechanges:=False End If Next End Sub追问
谢谢,如果要关闭已打开的所有文件,怎样写?
追答
Private Sub Workbook_Open() Dim Wb As Workbook For Each Wb In Workbooks If Wb.Name ThisWorkbook.Name Then Wb.Close '如果要强行不保存关闭,可以加上 savechanges:=False End If Next ThisWorkbook.close End Sub