Solved

Path in Microsoft Word Macro

Posted on 2013-05-31
4
22 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

830 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