Relative directories issue - Thisworkbook.path not working from .exe

Hi

My original code has a VBA script, which references an .xls file in another directory using the “Thisworkbook.path” keyword.

However, once I’ve compiled my workbook into an .exe, using Xls Padlock, and I try to run the .exe, the code attempts to access the workbook from the a:\ drive (a:\Office…) If I change “Thisworkbook.path” to “Activeworkbook.path”, which i think may be wrong, it now tries to access the file using the q:\ directory (q:\Office…).

Is there a way around this? I’d like to keep directory paths relative so that I can run my code wherever it gets pasted.

Kind regards
Spartan

Sorry I see now a similar question previously. I will try that solution and continue on that thread if there are further problems.

Kind regards
Spartan

Hi

I saw a work around in another post, which I tried to replicate.

However, I’m getting a further error. Runtime error 424 Object required. The program gets crashes on the bolded line. I definitely have the COM reference in VBA ticked under tools for the GXLSForm Library.

My code:

Public Function PathToFile(Filename As String)

Dim XLSPadlock As Object
Set XLSPadlock = Application.COMAddIns(“GXLSForm.GXLSFormula”).Object
PathToFile = XLSPadlock.PLEvalVar(“EXEPath”) & Filename

End Function

I tried replacing the bolded line with the following:

Set XLSPadlock = Application.COMAddIns.Item(“GXLSForm.GXLSFormula”).Object

Same problem. I also iterated through the COMAddIns collection to see if I had the library in the COMS list, and it does e.g.


a = Application.COMAddIns.Count
For i = 1 To a
b = Application.COMAddIns(i).progID
Cells(1, 1) = b
Next i

When I use a breakpoint, I can see the value of b and I do see that GXLSForm.GXLSFormula is in the list.

Please let me know if anyone has any clue what is wrong. I’ve setup a basic program with just this code. Im happy to email the two Excel files I’m testing on, its only about 25KB.

Kind regards
Spartan

The GXLSForm.GXLSFormula add-in is automatically installed in Excel by XLS Padlock Setup, so when you open your workbook in Excel, the add-in should be available and the code should work as expected.
If not, please run the XLS Padlock Manager (shortcut on your desktop) and verify that the two leds are green.
Have you also checked that GXLSForm is correctly appearing in your Excel’s COM add-in list?

In the compiled EXE file, GXLSForm.GXLSFormula is automatically emulated by the EXE and Excel recognizes it.

Hi

As per your email response:

I see when I pasted the quotes into VBA off the forum (or the help file), they pasted differently. So I had to replace the pasted quotes with quotes from my own keyboard (").

(1) Didn’t work - (“GXLSForm.GXLSFormula”).
(2) Worked - (“GXLSForm.GXLSFormula”). (I don’t know why the quote characters appear the same here, but they look different when editing).

I was then able to read the other file.

Thanks for your help!

Kind regards
Spartan