LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Check if file is open, if yes close woorkbook

Hi,
From my Mainworkbook the macro select some data, create a new file from this
then save as a new filename, close it, keeping the Mainworkbook open. Macro
continue and do the same process again using new data and save it as another
filename. He do this 5 times.
Problem:
If one of the file is already open by someone else the macro show an error
message and stop. How to check if the file is open? If it is open, just close
this workbook without saving it and continue with the macro to save the next
file.

If it is, I need to close this file to be able to get back on my main file
Here one part of the macro:

================

'First, the data is extract from the mainfile and copy to a new workbook
' now it's time to save this new file

Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=True, _
Filename:="G:\2009\Infos\ListeTSRs.xls"
Application.DisplayAlerts = True
=========================
' macro continue, using the main file, select the new data, create a file,
then
again save as a new name.
=================
 
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
Fix code - check to see if a workbook is open, if so, save changes then close. J.W. Aldridge Excel Programming 6 October 13th 07 07:22 PM
A check box to open and close Columns Steved Excel Programming 2 August 6th 07 08:18 AM
Close Open Woorkbook and Quit Excel Lucy[_2_] Excel Programming 5 December 24th 03 02:52 PM


All times are GMT +1. The time now is 01:58 AM.

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

About Us

"It's about Microsoft Excel"