LockXLS On-line Help Library

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

Save Workbook as unprotected file.

Excel File Compiler Screenshot

Sometimes you need to extract part of your workbook and make it's fomulas and VBA code available to customer. This sample describes how to copy worksheet into new file and save it as usual Excel workbook.

This project and all files (locked and unlocked ones) can be downloaded from our website using this link lockxls_samples.msi.

Macro, which performs SaveAs operation, assigned to button in our example:

' create new workbook
ThisWorkbook.Sheets("Sheet2").Copy
' save it and close

' declare variable for LockXLS Runtime object
Dim oLockXLS As Object
' create LockXLS Runtime object
Set oLockXLS = CreateObject("LockXLSRuntime.Connect")
' provide Unlock Code
oLockXLS.UnlockSaveAs ("UnlockCode")

Call Workbooks(2).SaveAs(ThisWorkbook.Path & "\Sheet2.xls")
Call Workbooks(2).Close(False)

' Lock SaveAs method again
oLockXLS.LockSaveAs
' release LockXLS Runtime object
Set oLockXLS = Nothing

Method UnlockSaveAs provides unlock code to LockXLS Runtime. In our example this string is "UnlockCode", in your workbook this should be your own unlock code, which should be kept in secret.

SaveAs method saves new workbook on disk and Close - closes it.

As a result of this macro file Sheet2.xls should appear in the same folder as source file.