LockXLS On-line Help Library

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

Working with locked linked workbooks.

Excel File Compiler Screenshot

This sample describes the most common case, with linked workbooks:

  • Formulas from one workbook refers to the cells from other one
  • One workbook opens other one using VBA macro and copies values to itself

So, we've added 3 files to this project:

  • MainWorkbook.xls
  • LinkedWorkbook.xls
  • Data.xls

MainWorkbook.xls and LinkedWorkbook.xls - are linked files, LinkedWorkbook has reference to MainWorkbook and MainWorkbook has reference to LinkedWorkbook. MainWorkbook.xls opens Data.xls located in same folder and copies range from this workbook to itself. This operation is assigned to Load Input Values from Data.xls button.

This project has Hardware Based Activation Code protection option.

You can convert all linked files to executables or lock then as usual Excel documents - linked workbooks work in both cases. Edit Links command finds linked workbook even it is locked as application. If some of your linked files should be opened separately - convert each of them to application.

Primary file MainWorkbook.xls which should be opened by customer is converted to application. Other files are converted to usual Excel documents.

To keep links, locked files should have same names. So we've create Output sub-folder for all locked files in our project.

The only modification we should make - is a code, which opens locked workbook:

' Find path to locked file Data.xls

' declare variable for LockXLS Runtime object
Dim oLockXLS As Object
' variable which contains path
Dim sPath As String
' create LockXLS Runtime object
Set oLockXLS = CreateObject("LockXLSRuntime.Connect")
' get path
sPath = oLockXLS.GetApplicationPath(ThisWorkbook)
' release LockXLS Runtime object
Set oLockXLS = Nothing
' open workbook and copy data to our sheet
Dim oWb As Workbook
Set oWb = Workbooks.Open(sPath & "Data.xls")
oWb.Sheets(1).Range("B5:B9").Copy
ThisWorkbook.Sheets(1).Range("B5").PasteSpecial
Call oWb.Close(False)
Set oWb = Nothing

Method GetApplicationPath returns folder, where locked application is located. If workbook is not locked it returns folder of this workbook.

Locked linked files work in same way as usual linked spreadsheets. We should not do any modifications to make locked files working.

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