Solved

Change directory in Macro Savefile

Posted on 2004-09-16
4
1,219 Views
Last Modified: 2008-02-01
Ok, I got this to work once, but now it won't work.  Please help.

I want this macro to save a file in a "peer" folder... that is, I need the save function to go up one directory and back down to another.  I would like to avoid using the entire path, but I will if necessary...

Here's some code.  A quick response (before 5pm) is an extra 100 points.

Sub GenDocs()

    Dim CurrDocName, CurrDocPath
    CurrDocName = ActiveDocument.Name
    CurrDocPath = ActiveDocument.Path

 'Save the "Clean" Version of the CurrentDoc
 'PROJECTFOLDER is a folder name declared elsewhere...
 'the problem is that the ..\ doesn't make the change directory thing go "up"
 
       ChangeFileOpenDirectory "..\" & PROJECTFOLDER & "\"
 
        ActiveDocument.SaveAs FileName:="T_" & CurrDocName
 
'Now save the redline version of the current doc, before we create the redlines...
        ChangeFileOpenDirectory "..\" & REDLINEFOLDER & "\"
        ActiveDocument.SaveAs FileName:="R_" & CurrDocName

'Now make the redlines        
        ActiveDocument.Compare Name:="..\" & ENABLERfolder & "\" & CurrDocName

'And save them
        ActiveDocument.Save
       
End Sub
0
Comment
Question by:epuglise
  • 2
4 Comments
 
LVL 9

Expert Comment

by:gilbar
Comment Utility
i'm not sure how'd you do this without the whole path, but if you do use the whole path, the changefileopendirectory statement should set the current directory to what you want.
0
 
LVL 1

Accepted Solution

by:
Kelly_in_Los_Angeles earned 200 total points
Comment Utility
Hi epuglise!

You wrote that...

>>'the problem is that the ..\ doesn't make the change directory thing go "up"
>>
>>       ChangeFileOpenDirectory "..\" & PROJECTFOLDER & "\"

But I am a little confused because the ".." (in fact your entire line) DOES work when I try it.

So I'm trying to think of reasons that it might not be working for you.

One possibility:
at the time that this line of code in this macro is trying to run, are you assuming that the folder that Word is in is the default document-saving folder?  For example, are you assuming that Word is in:
C:\Documents and Settings\User1\My Documents\SaveThemHere

and you expect your line of code to switch to:
C:\Documents and Settings\User1\My Documents\PROJECTFOLDER

(is that more or less a correct description of your situation?)

Because you may encounter problems if word is not "in" the folder you think it is.
To investigate this, you might try adding some lines immediately before the line with
ChangeFileOpenDirectory

you could add:
Debug.Print CurDir
Debug.Print Options.DefaultFilePath(wdDocumentsPath)

or:
MsgBox CurDir
MsgBox Options.DefaultFilePath(wdDocumentsPath)

(if you use Debug.Print you must have the "immediate window" open -- i think ctrl+g will open it)

So if you expect and NEED word to be "in" the typical/default saveas folder before the code in this macro can run properly, then add something like this to the macro:
ChangeFileOpenDirectory Options.DefaultFilePath(wdDocumentsPath)


0
 
LVL 1

Expert Comment

by:Kelly_in_Los_Angeles
Comment Utility
epuglise,

are you getting any error messages?  or does the whole macro run until completion?
if you get an error message, I would be curious to know what the message is.
if you don't get an error, then where are the files being saved?

Also,
are you absolutely sure that the PROJECTFOLDER variable contains the right string value?
For example, what if PROJECTFOLDER contains " "
of what if it contains "\projects\" and then your code adds "\" all over again to make \\projects\\ ?
0
 

Author Comment

by:epuglise
Comment Utility
Well, I'm glad to hear it worked for you LA Kelly.  That means I'm not crazy and it was working before.  Since it is so fragile, though and depends on where the user last was, I built a series of variables that check the current directory, find the "one up" directory by subtracting off the folder name of where the user should be (and warns the user if the file is not in the right place), and then builds the peer directories off the one up directory.  Long and kludgy but it works.


Interesting point about the default path.  I'll look into that.  Didn't know it might affect the save process.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

772 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

11 Experts available now in Live!

Get 1:1 Help Now