Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default 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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 341
Default 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?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA code is being deletd from WorkBook hhalle Excel Discussion (Misc queries) 1 February 1st 06 11:32 AM
Need to Improve Code Copying/Pasting Between Workbooks David Excel Discussion (Misc queries) 1 January 6th 06 03:56 AM
copy and paste using code from workbook to workbook bigdaddy3 Excel Discussion (Misc queries) 2 September 14th 05 11:06 AM
Often-Used Code not working in a new Workbook Steve Excel Discussion (Misc queries) 2 December 16th 04 11:55 PM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM


All times are GMT +1. The time now is 04:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"