Hi All,
I'm trying to test for an existing Excel instance with a specific workbook. Now I may have to deal with several instances of Excel open at the same time on the workstation. I would like a way in VBA to look through what excel instances are open see if the desired workbook has been opened in them. This isn't to be confused with having multiple workbooks open in the same instance. I have tried several different ways in vain, some of them iterated below. I would appreciate any work code examples explaining what an dumkoff I am.
...this never detects the open workbook
...this doesn't work either
I'm trying to test for an existing Excel instance with a specific workbook. Now I may have to deal with several instances of Excel open at the same time on the workstation. I would like a way in VBA to look through what excel instances are open see if the desired workbook has been opened in them. This isn't to be confused with having multiple workbooks open in the same instance. I have tried several different ways in vain, some of them iterated below. I would appreciate any work code examples explaining what an dumkoff I am.
...this never detects the open workbook
Code:
Function OpenBook(sBookName As String)
Dim k As Integer
'Checks the names of all open books
For k = 1 To Workbooks.Count
If Workbooks(k).Name = sBookName Then
' activate already open workbook
Workbooks(k).Activate
Exit Function
End If
Next k
' open workbook
RetVal = Shell(("EXCEL.EXE " + Chr(34) + sFileBasePath + sBookName + Chr(34)), 1)
' Workbooks.Open (sFileBasePath + sBookName)
End Function
...this doesn't work either
Code:
Sub TryThis()
Dim WIsOpen As Workbook
On Error Resume Next
Set WIsOpen = Workbooks("c:\sheets\Planners.xls")
If WIsOpen Is Nothing Then
MsgBox "I'm not Open"
Else
MsgBox "I'm already Open"
End If
On Error GoTo 0
End Sub
Last edited: