Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Is a file already open

how can I tell (with VB) if a file is already open?

Thanks,

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Is a file already open

Hi
try something like the following:

sub foo()
dim wbk as workbook
on error resume next
set wbk = workbooks("your_workbookname.xls")
if err.number<0 then
msgbox "Workbook is not open"
exit sub
end if
'now your other code
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


John T. wrote:
how can I tell (with VB) if a file is already open?

Thanks,

John

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Is a file already open

John,

Try something like

Function IsWorkbookOpen(WBName As String) As Boolean
On Error Resume Next
Dim L As Long
L = Len(Workbooks(WBName).Name)
If L = 0 And StrComp(Right$(WBName, 4), ".xls") < 0 Then
L = Len(Workbooks(WBName & ".xls").Name)
End If
IsWorkbookOpen = (L 0)
End Function

You can then call this function with code like

If IsWorkbookOpen("Book1") = True Then


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





"John T." wrote in message
...
how can I tell (with VB) if a file is already open?

Thanks,

John



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Is a file already open

The other interpretation of your question is if it is open, but not
necessarily in the instance of Excel containing the code. Then you could
use:

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


--
Regards,
Tom Ogilvy


"John T." wrote in message
...
how can I tell (with VB) if a file is already open?

Thanks,

John



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
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
excel 2003 saved file will not open without a blank workbook open Bob Excel Discussion (Misc queries) 4 November 11th 06 04:24 PM
In Excel - Use Windows Explorer instead of File Open to open file KymY Excel Discussion (Misc queries) 1 August 5th 06 09:59 PM
How do I stop Excel from closing the open file each time I open a. Welsin Setting up and Configuration of Excel 3 January 8th 05 11:16 PM


All times are GMT +1. The time now is 08:28 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"