All three of the IsOpen functions work for me. Note that if the
workbook you are testing for has been saved, you must include the
".xls" file extension in the BookName. For example,
If IsOpen("Book1.xls") = True Then ' note the ".xls"
will always work if the workbook has been saved, but
If IsOpen("Book1") = True Then ' note the missing ".xls"
may not work if the workbook has been saved. It depends on the
Windows Explorer "Hide extensions for known file types" setting.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"Rob" wrote in message
...
I want to test if a workbook is open. I've found these
suggestions, but none of them work for me. Any ideas why?
Thanks
Rob
'I've tried:
Function IsOpen(BookName As String) As Boolean
On Error Resume Next
Set wb = Workbooks(BookName)
IsOpen = Not wb Is Nothing
End Function
'and:
Function IsOpen(BookName As String) As Boolean
On Error Resume Next
IsOpen = Not (Application.Workbooks(BookName) Is Nothing)
End Function
'and:
Function IsOpen(BookName As String) As Boolean
On Error Resume Next
IsOpen = Len(Workbooks(BookName).Name)
End Function