Saturday, December 25, 2010

Macro : Check workbook open or not

Dim wBook As Workbook

On Error Resume Next
Set wBook = Workbooks(wfn & ".xls")

If wBook Is Nothing Then 'Not open
'MsgBox "Workbook is not open", _
vbCritical, "PSS Ltd"

Set wBook = Nothing
On Error GoTo 0
Else 'It is open
MsgBox "Workbook already in use by another user!" & Chr(10) & _
"Please try again later!", vbCritical, "PSS Ltd"
Set wBook = Nothing
On Error GoTo 0
End If

No comments: