LockXLS On-line Help Library

no items
folder
folder
folder
folder
no items
no items
no items

How to determine is opened workbook locked?

Excel File Compiler Screenshot

If you write a VBA macros in workbook which works differently in locked and in unlocked file, function IsWorkbookLocked can be used to determine if some workbook is locked.

LockXLSRuntime.IsWorkbookLocked( < workbook object > As Excel.Workbook ) As Boolean

workbook object is an object which represents workbook you want to check. This is not a workbook name!

Here is example of VBA code you may use:
' declare variable for LockXLS Runtime object
Dim oLockXLS As Object
' create LockXLS Runtime object
Set oLockXLS = CreateObject("LockXLSRuntime.Connect")
' determine if this workbook is locked
If oLockXLS.IsWorkbookLocked( ThisWorkbook ) Then
' code which works in locked version of file
...
Else
' code which works in unlocked version of file
...
EndIf
' release LockXLS Runtime object
Set oLockXLS = Nothing

Be careful if you are using Workbooks("WorkbookName") statement to get Workbook object. If workbook with this name is not opened, you will get "Subscript is out of range" error.

See Also

All methods of the LockXLS Runtime object