Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Testing if file is open

Hi - Does anyone know of any code that will check if an xls is open, and if
it is, close it?

Regards

Andrew


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Testing if file is open

In the same instance of excel or open anywhere on a network?

On Error Resume next
set bk = workbooks("ABCD.xls")
On error goto 0
if not bk is nothing then
bk.close SaveChanges:=False
End if

will do the first.


http://support.microsoft.com?kbid=138621
XL: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=291295
XL2002: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=213383
XL2000: Macro Code to Check Whether a File Is Already Open

http://support.microsoft.com?kbid=184982
WD97: VBA Function to Check If File or Document Is Open

will find if it is open anywhere. closing it would be another story. Why
not open it read only or make a copy or wait your turn.

--
Regards,
Tom Ogilvy

"andreww" wrote in message
...
Hi - Does anyone know of any code that will check if an xls is open, and

if
it is, close it?

Regards

Andrew




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Testing if file is open

Andrew,

Try something like

On Error Resume Next
Workbooks("BookName.xls").Close savechanges:= True ' or false
On Error Goto 0


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"andreww" wrote in message
...
Hi - Does anyone know of any code that will check if an xls is
open, and if it is, close it?

Regards

Andrew



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
testing. do not open. S S Excel Worksheet Functions 1 April 16th 06 01:16 AM
Testing for an open file Nigel Excel Programming 3 July 11th 05 06:41 AM
Testing if a file is open John Baker Excel Programming 3 January 29th 04 01:26 AM
Testing for a open worksheet from Outlook Phillips[_3_] Excel Programming 1 December 30th 03 07:45 AM
Testing for open workbook nigelab Excel Programming 4 November 2nd 03 04:31 PM


All times are GMT +1. The time now is 12:52 AM.

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"