VBA code ThisWorkbook.Path does not work - SOLVED


#1

Hello,

I have created two EXE files from Excel files.

In one file I have a vba code and with a command button I want to open the second exe file.

In order to get this I use the following code:

Sub tsh()
Dim strProgramName As String

strProgramName = ThisWorkbook.Path & "\voorbeeldexe.exe"
Call Shell(strProgramName, vbNormalFocus)
ThisWorkbook.Save
Application.Quit

End Sub

Problem is that the “This workbook.path” give me an error message. I think it’s because the exe is not a “workbook”… Any idea how can solve this problem?


#2

You are right: ThisWorkbook.Path won’t work here. You can find the solution in the XLS Padlock user guide:

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

Insert the following code:

Public Function PathToFile(Filename As String)
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


#3

Thank you :slight_smile:


#4

In the same theme i have an error who prompt when i click a button to open an pdf file.

“Compilation error. sub or function not defined.”

This is my VBA code :

Sub link_pdf()
Dim adresse As String
adresse = "WikiEvalMat.pdf"
Call PathToFile(adresse)
If adresse = “” Then
Exit Sub
Else
ActiveWorkbook.FollowHyperlink Address:=adresse
End If
End Sub

And the function :

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

Do you see a trouble Thanks


#5

ActiveWorkbook.FollowHyperlink Address:=adresse there is the error, i think the 'ActiveWorkbook" doesn’t work. Do you have a idea please?

This sub is to open a pdf file.

Thank you


#6

For answer, shall i create a new post?


#7

Yes you can