PDA

View Full Version : Help w/ Saving Document



thesoxman
03-08-2006, 05:26 PM
Hey all,

I've run into a little bit of trouble here and hoping somebody can help. Basically I have a catalogue generator that generates various catalogues based on data passed into the document. So my function looks like:

Sub AutoOpen()
Call Catalogue("256")
Call Catalogue("123")
End Sub

Sub Catalogue(cartype)
....
...

Now my problem is that when the first instance of Catalogue is run it needs to be saved but then continue the macro on the ORIGINAL file. But using:

ActiveDocument.SaveAs(Filename)

makes the saved document the active one and therefore the script gets an error because the .ini file used to define other variables is located w/ the original file, not the new saved file. I have considered saving the New Catalogue document to the same directory as the original, but this isn't viable since when i open the new document the macro will run all over again and i'll lose the orignal work.

I know it's confusing but need a solution
Thanks

fumei
03-08-2006, 11:22 PM
Yes it is confusing, and it is your responsibility to make it not so. Walk it through step by step. Tell us what you are doing exactly, and when you are doing it. Be reasonable, do you really think:

Sub AutoOpen()
Call Catalogue("256")
Call Catalogue("123")
End Sub

Sub Catalogue(cartype)
....
...

tell us ANYTHING? It tells us very very little. We have NO idea when your instruction ActiveDocument.SaveAs runs.

You mention an .INI file...that is nice, but under the circumstances mentioning it is more frustrating than helpful, as " is located w/ the original file" means nothing. What does "located with" mean???? If it means it is in the same folder as the "original" file....who cares? It is a separate file (assumably). If it is a separate file it can be referenced again.

HOWEVER, while I admit that was a rant, here is a suggestion. If you have an "original" document and you ever want to changes things and do a save of the changes, BUT somehow save the original, then you can:

Create a new document and copy the contents of the original over to that, THEN do a SaveAs.

An alternative - and I am surprised not more people use this technique - is to use Document objects.Dim ThisDoc As Word.Document
Dim ThatDoc As Word.Document
Set ThisDoc = ActiveDocument
Documents.Add
Set ThatDoc = ActiveDocument
ThatDoc.Content = ThisDoc.Content

Set ThatDoc = Nothing
Set ThisDoc = NothingWhat this does is make a document object of the document you are starting with; then make a new document; and a document object for that. Then the code explicitly states that the content of the second document object equals the contents of the first document object.

Once stated...it IS. Now you can action the second document, even from code in the first. This is because it is a document object.