Link to home
Start Free TrialLog in
Avatar of epuglise
epuglise

asked on

Change directory in Macro Savefile

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
Avatar of gilbar
gilbar

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.
ASKER CERTIFIED SOLUTION
Avatar of Kelly_in_Los_Angeles
Kelly_in_Los_Angeles

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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\\ ?
Avatar of epuglise

ASKER

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.