ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Testing if file is open (https://www.excelbanter.com/excel-programming/335682-testing-if-file-open.html)

andreww

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



Tom Ogilvy

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





Chip Pearson

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





All times are GMT +1. The time now is 01:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com