Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6600083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:34:31+00:00 2026-05-25T18:34:31+00:00

I am currently using VBA code which was originally intended for an excel document.

  • 0

I am currently using VBA code which was originally intended for an excel document. I could just retailor the code for use in word but I think it might be better to extend the application so that it is compatible to ‘potentially’ any MS Office Application. But I’m not entirely sure how to do so.

For example the excel based code fetches the document’s path:

If libDir = "" Then libDir = ThisWorkbook.Path

To extend this to word I just have to replace ThisWorkbook with ActiveDocument.

But would it be possible to find out which office application is running the VBA code so that I can keep both.

 'IF VBA run from Word Then
     If libDir = "" Then libDir = ThisWorkbook.Path
 'ELSE VBA run from Excel then
     If libDir = "" Then libDir = ActiveDocument.path
 'End If

So far I can see that I can find out if word or excel is open but I cannot assume that because it is open it is running that specific module. But that is beyond my VBA knowledge.

I’ve also tried this currentproject.path but that doesn’t work.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:34:32+00:00Added an answer on May 25, 2026 at 6:34 pm

    It does sound complex trying to tool up code to suit various Office APPs. And what does this code do if it can be applied in word and excel – perhaps vbscript and then automating the object you want to work with is an option

    On your specific example above, it will actually compile okay (and I haved tested in xl2003, xl2010 and word2010), so with error handling the code will run and skip the otherwise problematic areas.

     On Error Resume Next
        If libDir = "" Then libDir = ThisWorkbook.Path
        If libDir = "" Then libDir = ActiveDocument.Path
     On Error GoTo 0
    

    Something else to consider, the Path wont exist if the file is unsaved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following vba-code in an MS-Access97-frontend which opens a word-document stored on
Using VBA I want to send a copy of the current word document to
Using Application.Quit in Excel VBA is supposed to initiate the default quit procedure, which
Currently using Google Analytics as a supplement to our paid tracking software, but neither
I'm currently using the awesome attachment-fu plugin for a Rails app, but as a
I am using the code below to call a query in Access VBA strSQL
The following Visio macro (using VBA) rotates the currently selected shape: ActiveWindow.Selection.Rotate90 How can
I'd like to be able to source control my Excel spreadsheet's VBA modules (currently
I'm currently writing a code in VBA to retrieve prices for some financial models.
I am using Excel 2003 to connect to a SYBASE database using a VBA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.