Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Path in Microsoft Word Macro

Posted on 2013-05-31
4
Medium Priority
?
28 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
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…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

715 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