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
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
''
***************************************************************************
'' Purpose : Test if a specific file is open
'' Written : 29-Jun-2001 by Andy Wiggins
'' Syntax : IsWindowOpen("FileName.Xls")
'' Returns : "True" or "False"
''
Function IsWindowOpen(pstr_WindowName As String)
Dim w As Window
For Each w In Windows
If w.Caption = pstr_WindowName Then
IsWindowOpen = True
Exit Function
End If
Next
IsWindowOpen = False
End Function
--
Regards
Andy Wiggins www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.