View Full Version : Solved: Detect if a workbook is open
alimcpill
01-06-2006, 03:50 AM
Please help:
I need to be able to check using code if a particular workbook is in use. Surely this should be easy to do? I can't seem to work it out!
alimcpill
01-06-2006, 04:03 AM
Sorry, I solved it minutes after posting. Probably not bulletproof but good enough for my needs.
Mods remove this post if you want.
ta
Al
Public Function IsWorkbookReady(strWbPath As String) As Boolean
Dim objXl As Excel.Application
Dim objWb As Excel.Workbook
Set objXl = New Excel.Application
'objXl.Visible = True 'true for debugging
objXl.DisplayAlerts = False
On Error GoTo IsWorkBookReady_Error
Set objWb = objXl.Workbooks.Open(strWbPath, , False)
If objWb.ReadOnly Then
IsWorkbookReady = False
Else
IsWorkbookReady = True
End If
objWb.Close False
On Error GoTo 0
Resume_IsWorkbookReady:
On Error Resume Next
objWb.Close False
On Error GoTo 0
objXl.Quit
Set objWb = Nothing
Set objXl = Nothing
Exit Function
IsWorkBookReady_Error:
IsWorkbookReady = False
Resume Resume_IsWorkbookReady
End Function
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.