Solved

Path in Microsoft Word Macro

Posted on 2013-05-31
4
20 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
4 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 250 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 250 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

773 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