Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Path in Microsoft Word Macro

Posted on 2013-05-31
4
Medium Priority
?
30 Views
Last Modified: 2016-04-11
I've been using a Macro in Word since 1997. It began life as Word Basic and got converted by a later version of Word.
The document/macro is on a USB stick, so, depending on the PC or laptop I use it could be drive E, J, K, L or maybe something else on someone else's PC.
I have a line at the beginning to set the path which says
ChangeFileOpenDirectory "J:\Showprog"
so if it turns out to be on drive K it returns an error and I have to manually change it to K or whatever is appropriate - until the next time....
What line(s) should I have so that I don't have this bother - I think it is something to do with current document or something.
0
Comment
Question by:WalterMaxey
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 1000 total points
ID: 39212308
Give the path property of the ThisDocument object a try:

ChangeFileOpenDirectory ThisDocument.Path & "\Showprog"

Open in new window

1
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 1000 total points
ID: 39225474
Assuming you could be opening a file in the subfolders of the flash drive then the following function will return the drive letter (and :) else return the full path if there is no drive identified.

Use in the context of your question for example as:

ChangeFileOpenDirectory getdrive(thisdocument) & "\showprog"

Function getDrive(doc As Document) As String
'msgbox getdrive(thisdocument) & "\showprog"
    If InStr(doc.Path, ":") > 1 Then
        getDrive = Split(doc.Path, ":")(0) & ":"
    Else
        getDrive = doc.Path
    End If

End Function

Open in new window


Chris
1
 
LVL 14

Expert Comment

by:frankhelk
ID: 41544439
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question