Get the path to a file in the same folder as the compiled workbook

 

Purpose: get the path to a file in the same folder as the compiled workbook

Insert the following code:

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

 


Copyright © 2021 G.D.G. Software