Results 1 to 7 of 7

Thread: Find VBA application path

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Southern California
    Posts
    2

    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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    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
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2007
    Location
    Southern California
    Posts
    2

    Arrow 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?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,710

    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?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    New Member
    Join Date
    Dec 2007
    Posts
    2

    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!!

  6. #6
    New Member
    Join Date
    Aug 2010
    Posts
    1

    Re: Find VBA application path

    Application.CurrentProject.Path

  7. #7
    New Member
    Join Date
    Dec 2007
    Posts
    2

    Re: Find VBA application path

    Quote Originally Posted by jy0tsna View Post
    Application.CurrentProject.Path
    I see you didn't read the above post regarding context.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width