PDA

View Full Version : Solved: This is very easy for somebody but not me



glinch
06-30-2009, 05:36 PM
My head is starting to hurt now, trying to find out how to do something that must be very easy to do.

Put simply, im using a macro to save a file to a "sent" folder that is all ready created, all i want to do is change directory

ChangeFileOpenDirectory _
"C:\Documents and Settings\sent\"

how do i use a relative file path to the document

ie (Although this doesnt work obviously!)

ChangeFileOpenDirectory _
"CURRENT FOLDER\sent\"

Cant figure or find out how to do relative paths

Thanks to anyone in advance who helps a simpleton!

Oorang
06-30-2009, 08:30 PM
This won't work if the document hasn't been saved yet (new) because there is no path yet, but it should do the trick for saved docs.
Dim strPath As String
strPath = ThisDocument.Path & "\Sent"

glinch
07-01-2009, 02:21 AM
Cheers for the help Aaron, but i cant get it to work

The document is saved in a folder, with a folder named "sent" residing in the same folder

Dim strPath As String
strPath = ThisDocument.Path & "\sent"
ChangeFileOpenDirectory strPath
ActiveDocument.SaveAs FileName:=ActiveDocument.Name, FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=FalseActiveDocument.Name
Dialogs(wdDialogFilePrint).Show

Get the message cant find path ?

Oorang
07-01-2009, 10:14 AM
Looks like you forget to update the FileName parameter of the SaveAs method to use the strPath variable;)

glinch
07-01-2009, 02:43 PM
Sorry if this trying your patience Aaron, and i appreciate your help with this big time.

I cant see how its that part of the code that is stopping it working as this code below gives the same error message

Sub Send_To_Clients()
'
' Send_To_Clients Macro
'
'
Dim strPath As String
strPath = ThisDocument.Path & "\sent"
ChangeFileOpenDirectory _
strPath

Dialogs(wdDialogFilePrint).Show
End Sub


...and there definitely is a folder in the root directory called "sent" (i know the code above doesnt really do much, but testing for errors adding the '& "\sent" ' seems to cause the error, remove this and there is no error. but it wont go to the directory i need!)

fumei
07-02-2009, 10:57 AM
1. Is, in fact, the path to the Sent folder the same path to the existing ActiveDocument? That is what ThisDocument.Path means.

"there definitely is a folder in the root directory called "sent""

There very well may be...but ThisDocument.Path returns the path to the current ActiveDocument, nothing more. If that document is not in the "root", then...there may indeed be a sent folder off the root, but it is irrelevant.

2. You do not really need to use ChangeFileOpenDirectory. In fact, I have never really understood why people do that. Look at the name ChangeFileOpenDirectory. I fail to see why people use a setting for FileOPEN....when what they are doing is saving a file...not opening one.

3. Paths are strings. A string variable can be whatever you want it to be.

"Cant figure or find out how to do relative paths"

You can not use relative paths with SaveAs. The parameter Filename:= requires an explicit - and valid - string, and is the path AND filename. In other words, the parameter Filename:= is the full path and filename of the file that is being SavedAs.

Please explain EXACTLY what it is you want to do. Hopefully, the following may help.

1. is the Path of the current active document relevant? If it is, yes, you can get the path with ActiveDocument.Path. Note however, that it does NOT include the separator. say the file is:

C:\ZZZ\Chris\Yadda yadda blahTEST.doc

ActiveDocument.Path = C:\ZZZ\Chris (NO \!)
ActiveDocument.Name = Yadda yadda blahTEST.doc

You are not totally clear, so I will make the following assumption.

- the "Sent" folder is a sub-folder to the folder that has the current (Active) document. If this is true, and you want to SaveAs the current ActiveDocument to this folder, then:
Dim strPath As String
strPath = ActiveDocument.Path & "\Sent\"
ActiveDocument.SaveAs _
FileName:=strPath & ActiveDocument.Name
Done. The current active document will be saved with the same name to a sub-folder ("Sent") of the folder the current ActiveDocument is in.

You can "send" a SavedAs file to any folder you want. All you need is the string that is that folder name. You must remember to add the "\" though.

glinch
07-05-2009, 08:58 AM
fumei brilliant, thanks a million for the very clear explanation to what I have been having a great deal of trouble with.

Aaron thanks for your help as well

Cheers