LockXLS On-line Help Library

Welcome
Getting Started
Using LockXLS
How to ...
General Questions
Questions about LockXLS activation
Advanced Questions
LockXLS Runtime Menu
Samples
About LockXLS
Purchase
Contact
Create unlocked workbook from VBA macro in locked file.

Create unlocked workbook from VBA macro in locked file.

In some cases you need to create a new workbook and copy some data from locked workbook to unlocked one. By default this new file is locked with settings copied from source workbook. To make this file unlocked you should use LockXLSRuntime.UnlockWorkbook method.

LockXLSRuntime.UnlockWorkbook( < workbook object > As Excel.Workbook )

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

IMPORTANT!
This call should be made only from locked workbook, which was a source for this new workbook. If this call (LockXLSRuntime.UnlockWorkbook) is made from unlocked file or from workbook locked with other settings, it will take no effect.
Here is example of VBA code you may use:
This code copies a sheet from locked file to new workbook and then unlocks it.
Dim nWorkbookCount As Integer
nWorkbookCount = Application.Workbooks.Count
' copy sheet to new workbook
Sheets("Sheet2").Copy
' get object of new workbook
Dim oWorkbook As Excel.Workbook
Set oWorkbook = Application.Workbooks(nWorkbookCount + 1)
' -------------------------------------------
' declare variable for LockXLS Runtime object
Dim oLockXLS As Object
' create LockXLS Runtime object
Set oLockXLS = CreateObject("LockXLSRuntime.Connect")
' unlock new workbook
Call oLockXLS.UnlockWorkbook(oWorkbook)
Set oWorkbook = Nothing
' 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