Solved

Change directory in Macro Savefile

Posted on 2004-09-16
4
1,226 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
ID: 12078556
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
ID: 12078696
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
ID: 12078737
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
ID: 12079063
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

839 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