XLS Padlock Guide
XLS Padlock Guide

Why is ThisWorkbook.Path not working?

 

 

XLS Padlock works with virtualization: when the compiled workbook is run, the Excel file is virtualized at a random location. It is never unpacked to the hard disk and thus, ThisWorkbook.Path will not point to a physical location on the disk but to the virtual location.

As a workaround, if you want to get the path to the compiled workbook (which is your EXE file), XLS Padlock provides you with VBA code that you can use in your workbooks:

Public Function PathToFile(Filename As String)
Dim XLSPadlock As Object
On Error GoTo Err
Set XLSPadlock = Application.COMAddIns("GXLSForm.GXLSFormula").Object
PathToFile = XLSPadlock.PLEvalVar("EXEPath") & Filename
Exit Function
Err:
PathToFile = ""
End Function
 

 

You can then call the function:

Sub Test_File()
 DoSomethingWith(PathToFile("data.xls"))
End Sub
 

 

If you want the path to the folder that contains the EXE, use:

PathToFile("")