Solved

Change directory in Macro Savefile

Posted on 2004-09-16
4
1,228 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: 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

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…
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 …
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 …

679 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