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

Hi,

Can someone provide some direction on how to test if an Excel file is
currently open....not worried about whether it is active, just currently open.

I'm requesting the information from VBA for Word 2000. I've tried the
following:

if Excel.application.workbooks(vFileName).open = true
....
End if

It isn't working!

Any ideas would be very much appreciated.

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

Try either of the following functions.

This is used if you pass only the name (e.g., "Book2.xls") to the function,
with no file folder/path information.
Function IsWorkbookOpen(WBName As String) As Boolean
On Error Resume Next
IsWorkbookOpen = CBool(Len(Excel.Application.Workbooks(WBName).Name ))
End Function

This is used for either just the name (e.g., "Book2.xls") or the full file
name (e.g., "C:\Test\Book2.xls").
Function IsWorkbookOpen2(FileName As String) As Boolean
Dim WB As Excel.Workbook
For Each WB In Excel.Application.Workbooks
If (StrComp(WB.Name, FileName, vbTextCompare) = 0) Or _
(StrComp(WB.FullName, FileName, vbTextCompare) = 0) Then
IsWorkbookOpen2 = True
Exit Function
End If
Next WB
End Function


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"jille" wrote in message
...
Hi,

Can someone provide some direction on how to test if an Excel file is
currently open....not worried about whether it is active, just currently
open.

I'm requesting the information from VBA for Word 2000. I've tried the
following:

if Excel.application.workbooks(vFileName).open = true
...
End if

It isn't working!

Any ideas would be very much appreciated.

Thanks,
Jille



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


Dim bk as Excel.Workbook

sPath = "C:\MyFolder\"
vFileName = "MyBook.xls"

On error Resume Next
set bk = Excel.Application.Workbooks(vFileName)
On Error goto 0
if not bk is nothing then
msgbox bk.Name & " is open"
else
set bk = Excel.Application.Workbooks.Open(sPath & vFileName)
end if



--
Regards,
Tom Ogilvy



"jille" wrote in message
...
Hi,

Can someone provide some direction on how to test if an Excel file is
currently open....not worried about whether it is active, just currently
open.

I'm requesting the information from VBA for Word 2000. I've tried the
following:

if Excel.application.workbooks(vFileName).open = true
...
End if

It isn't working!

Any ideas would be very much appreciated.

Thanks,
Jille



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 if file is open andreww Excel Programming 2 July 27th 05 06:07 PM
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 open workbook nigelab Excel Programming 4 November 2nd 03 04:31 PM


All times are GMT +1. The time now is 10:43 PM.

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"