If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Detecting file Open status

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-04, 21:50
tmccollum tmccollum is offline
Registered User
 
Join Date: Nov 2004
Posts: 32
Detecting file Open status

I need to detect if a particular Excel file is currently open useing VBA. Can anyone help as to which property to reference???
Reply With Quote
  #2 (permalink)  
Old 12-08-04, 22:56
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
I use this function.
You'd might call it Like this:

If WorkbookIsOpen("somebook.xls") Then
Workbooks("somebook.xls").Activate
Else
Workbooks.Open FileName:="c:/My Documents/somebook.xls", _
ReadOnly:=False, Notify:=False
End If


Code:
'
Function WorkbookIsOpen(wbname) As Boolean
'   Returns TRUE if the workbook is open
    Dim x As Workbook
    On Error Resume Next
    Set x = Workbooks(wbname)
    If Err = 0 Then WorkbookIsOpen = True _
        Else WorkbookIsOpen = False
End Function
__________________
~

Bill
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On