![]() |
Ignoring code to shut a workbook if it is already shut
I have some coding which closes and saves workbooks;
Workbooks("Bund Current Payoff.xls").Close SaveChanges:=True etc but I want the code not to have an error and have a problem if the file has already been closed when the code is run. How do I get around this problem? |
Ignoring code to shut a workbook if it is already shut
Test if the workbook is still open first:
Dim wbTest As Workbook on error resume next Set wbTest = Workbooks("Bund Current Payoff.xls") on error goto 0 If Not wbTest Is Nothing Then Workbooks("Bund Current Payoff.xls").Close SaveChanges:=True wbTest will be Nothing if it wasn't already open -- Allllen "Cammy" wrote: I have some coding which closes and saves workbooks; Workbooks("Bund Current Payoff.xls").Close SaveChanges:=True etc but I want the code not to have an error and have a problem if the file has already been closed when the code is run. How do I get around this problem? |
All times are GMT +1. The time now is 06:12 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com