Find VBA application path
I have a VBA application to be used in AutoCAD. The application has several data files that must be opened and read by the VBA application. I propose to have users install the files in the folder with the VBA project file. How can I obtain the path to the VBA project executable file?
Re: Find VBA application path
Welcome to the Forums.
Depending on the VBA app you can use either of these to get what you need.
Office:
MsgBox Application.Path
Excel:
MsgBox Application.ThisWorkbook.Path
Word:
MsgBox Application.ActiveDocument.Path
Re: Find VBA application path
Thanks for the quick response, but the answer did not address what I was seeking. "MsgBox Application.Path" returns he path to the Autocad program. In an Excel VBA application, I believe it would return the path to the Excel program files.
I am seeking a way to determine the path to my VBA code executable, which is a *.dvb file, stored in a folder outside the Autocad or Excel application with which it interacts.
Does anyone know of a way to return this path?
Re: Find VBA application path
I posted other methods too in my previous post. I dont have Autocad so I am not sure what the child object would be but it would probably be similar to the examples I posted for Excel and Word.
Probably something like Application.ActiveDrawing.Path or Application.ThisDrawing.Path?
Re: Find VBA application path
Quote:
Originally Posted by RobDog888
I posted other methods too in my previous post. I dont have Autocad so I am not sure what the child object would be but it would probably be similar to the examples I posted for Excel and Word.
Probably something like Application.ActiveDrawing.Path or Application.ThisDrawing.Path?
It's not going to be directly under the application object; just about everything that's a child of the application object is going to be under the AutoCAD application root dir - not where he wants be - and the VBE object is wonky to access directly. :) Here's how to do it under AutoCAD 2008 Civil 3d (Also tested with ACAD 2006)
Under AutoCAD VBA, all the vb code runs in the context of the editor, even if it's not visible. Here's how to get the dir you're looking for:
1. Under Tools, add a reference to 'Microsoft Visual Basic for Applications Extensibility 5.3'
2. Get the Dir your VBA app is executing in like so:
Dim objVBE as VBE
Set objVBE = Application.VBE
MsgBox objVBE.ActiveVBProject.FileName
...this will return the complete path of the current VBA app; just knock the file off the end of the string, and you have it.
Peace!!
Re: Find VBA application path
Application.CurrentProject.Path
Re: Find VBA application path
Quote:
Originally Posted by
jy0tsna
Application.CurrentProject.Path
I see you didn't read the above post regarding context.