Pad naar een bestand in de map van de EXE ophalen met VBA
Deze VBA-functie haalt het volledige pad op naar een bestand dat zich in dezelfde map bevindt als de EXE van uw toepassing. Ze is bijzonder nuttig om toegang te krijgen tot externe bronnen of begeleidende bestanden die u samen met uw beschermde werkmap distribueert.
👉 Voeg de volgende functie in een VBA-module in:
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 FunctionVervolgens kunt u de functie aanroepen:
Sub Test_File() DoSomethingWith(PathToFile("data.xls"))End Sub👉 Zie ook: VBA API Cookbook & Recipes