Get Path to a File in the EXE's Folder with VBA
This VBA function retrieves the full path to a file located in the same directory as your application’s EXE. It is particularly useful for accessing external resources or companion files that you distribute alongside your protected workbook.
👉 Insert the following function into a VBA module:
Public Function PathToFile(ByVal Filename As String) As String Dim XLSPadlock As Object Dim exePath As String On Error GoTo Err
Set XLSPadlock = Application.COMAddIns("GXLSForm.GXLSFormula").Object exePath = XLSPadlock.PLEvalVar("EXEPath")
' Use Application.BuildPath to correctly join the path and filename PathToFile = Application.BuildPath(exePath, Filename)
Exit FunctionErr: PathToFile = ""End FunctionYou can then call the function:
Sub Test_File() DoSomethingWith(PathToFile("data.xls"))End Sub👉 See Also: VBA API Cookbook & Recipes