Solved

Path in Microsoft Word Macro

Posted on 2013-05-31
4
15 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
Comment Utility
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
Comment Utility
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 13

Expert Comment

by:frankhelk
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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 …

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now