PDA

View Full Version : Save word.doc in a new directory...



irisbu
08-30-2007, 04:54 AM
my document "word.doc" is in directory d:\

I need a macro that saves it in a new directory: d:\new without using the save as function.

can enybody help me please?

lucas
08-30-2007, 08:56 AM
This uses the saveas but it makes a copy of the file in d:\ first and then uses saveas on the copy...closes the copy and reactivates your original file in d:\

There is no...savecopyas for word as there is in Excel so you have to use a workaround. Make a copy of the file and then saveas the copy...then close the copy.

Sub a()
Application.Documents.Add ActiveDocument.FullName
ActiveDocument.SaveAs FileName:="d:\new\" & "test"
ActiveDocument.Close
End Sub

irisbu
08-30-2007, 10:11 AM
This is great, but I am afraid not exactly what I need... What I need is for the document to be saved in another directory with all it's original properties... especialy the revision number... and that seems to be a real problem with the saveas property...

I thank you for your answer and I will be gratefull if you can find a solution to this problem.

thanks Iris

lucas
08-30-2007, 10:48 AM
I don't understand. It does save the file exactly as it is when you run the macro....what do you mean by original properties?

What do you mean by revision number? Is that text in the document? Is that what you want the file name to be saved as?

Please be specific as to what you are trying to do..

irisbu
08-30-2007, 10:55 AM
the revisionnumber changes... when you save the document with saveas... the revision number starts from 1 again... I need the revision number not to change back to one... I need the actual number of times this document was changed... I hope now I exlained it better...

lucas
08-30-2007, 11:25 AM
Document properties...ok give me some time...I just got busy here so I will revisit this.

irisbu
08-30-2007, 11:57 AM
OK... Thank you for your efforts!!

lucas
08-30-2007, 12:06 PM
Take a look at this one by Jake. it creates the copy when you try to save the active document.

I would also look into saving to an incremented file name if you wish to keep these because the way you are doing it you will overwrite any previous files each time...which may be ok in your case

http://www.vbaexpress.com/kb/getarticle.php?kb_id=203

fumei
09-01-2007, 11:55 AM
Ummm, why not just copy the file to the new location? Not a Word SaveAs, but a OS level filecopy.

lucas
09-01-2007, 02:22 PM
I looked at it Gerry but I ran into this in the help file:


If you try to use the FileCopy statement on a currently open file, an error occurs.

fumei
09-02-2007, 10:11 AM
Yes, indeed it does. So grab both the Name, and the FullName of the current file, close it. Open a blank doc (as there has to be a document open to use FileCopy - why I have no idea), do the filecopy, then re-open the document. Like this:Sub CopyCurrentFile()
Dim strShort As String
Dim strFull As String
strFull = ActiveDocument.FullName
strShort = ActiveDocument.Name
ActiveDocument.Close wdDoNotSaveChanges
Documents.Add
FileCopy strFull, "c:\" & strShort
RecentFiles(1).Open
End SubCopies the current file to c:\.

You may of course want to save the file first so the copy is exactly that. The code above does NOT save the file first. Adjust accordingly.

You may also want to set a Document object for the blank document (Documents.Add), then re-open the current file, and dump the blank one.

Again, adjust accordingly. Perhaps like:Sub CopyCurrentFile()
Dim TempDoc As Document
Dim strShort As String
Dim strFull As String
strFull = ActiveDocument.FullName
strShort = ActiveDocument.Name
ActiveDocument.Save
ActiveDocument.Close
Set TempDoc = Documents.Add
FileCopy strFull, "c:\" & strShort
TempDoc.Close wdDoNotSaveChanges
RecentFiles(1).Open
End SubObviously this procedure must be either normal.dot, or a global template. It can not be in the document that is being copied....as you are closing it.

irisbu
09-02-2007, 10:22 AM
because the user does not know where to save the document... I don't want him to use the exlorer... "just press a button and it will be done!"

irisbu
09-02-2007, 10:24 AM
let you know if I succided...

fumei
09-03-2007, 08:05 PM
because the user does not know where to save the document... I don't want him to use the exlorer... "just press a button and it will be done!"Huh? So what? Why are you saying this? I do not get the reference to the badly spelled "exlorer". I presume you actually mean Explorer. And...what has that to do with anything??? No one has mentioned the use of Explorer. None of the code posted here has anything to do with Explorer, so why are you mentioning it?

Change the code to the folder you actually want to have the file in! Boom, done. The user does indeed press a button and nothing else.

What is your problem exactly?

irisbu
09-03-2007, 11:48 PM
I deed meen explorer... jus a typing mistake... sorry.... and you are right... it dose work - thank you very much!!