View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Kanan Kanan is offline
external usenet poster
 
Posts: 34
Default how tell if file already open?

your code will work without the .xls extension in the isopen call.
just fyi
kanan

"David" wrote:

?B?SWFuIEVsbGlvdHQ=?= wrote

Thanks for any help.
I have a macro that pastes some info into another workbook. I open the
workbook, then run the macro. I would like to make the macro code to
open the file if not already open. If I make the code open a file
without checking if it is already open, I would get a notice about
opening it twice. So I would like to code it so that it checks if the
file is already open. How do I tell if a file is already open? With
workbooks.something? Or windows.something? Thanks.


I'm currently using the following Function I found (wish I could credit the
author):

Function IsOpen(ByRef BookName As String) As Boolean
On Error Resume Next
IsOpen = Not (Application.Workbooks(BookName) Is Nothing)
End Function

Called like this:

If IsOpen("yourfilename.xls") Then
'<your code here
Else
Workbooks.Open "yourfilename.xls"
End If

--
David