LockXLS On-line Help Library

Getting Started
Using LockXLS
How to ...
General Questions
Questions about LockXLS activation
Advanced Questions
LockXLS Runtime Menu
About LockXLS
How to determine is opened workbook locked?

How to determine is opened workbook locked?

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
' code which works in unlocked version of file
' 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