Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change directory in Macro Savefile

Posted on 2004-09-16
4
Medium Priority
?
1,252 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 800 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
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 and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
Suggested Courses

916 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