PDA

View Full Version : Solved: Save all



espencer
08-11-2005, 09:28 AM
Hello,
I have an application that opens a session WORD and in the open session of WORD download 23 new word documents. Is there a way with a macro to save all 23 documents without clicking the X and reply to dialog box to save. This process takes too long to do. Any help would be much appreciated

TonyJollans
08-11-2005, 10:28 AM
As these are new documents, you must somehow specify the name and location to avoid the dialogs.

Of course most things can be done in VBA, but even without that, Save All (which is available by pressing Shift and selecting the File menu) will eliminate all the pressing of Xs.

If you post back with details of how to determine the names, someone can easily knock up some code to save them.

espencer
08-11-2005, 11:18 AM
The application lets the user select the path of the folder and the names are letter01 - letter23. I hope this enough information.

TonyJollans
08-11-2005, 12:01 PM
Hi espencer,

Well not really. What sort of application is this? If it lets the user choose the path, does it not then save the documents to that path (otherwise why ask for it)?

Anyway, this code should be a start. It will save all open documents as letter01, letter02, etc. - at the moment to Word's default path - but which document gets which sequence number is random. With some more information I'm sure it can be made to be what you want.

Dim doc As Document

Dim path As String ' Don't know where to get this from at the moment
path = Options.DefaultFilePath(wdDocumentsPath) ' for now

Dim seq As Long
seq = 0

For Each doc In Documents
seq = seq + 1
doc.SaveAs path & "\letter" & Format(seq, "00")
Next

espencer
08-11-2005, 12:10 PM
This application was created from Oracle and lets the user set the path of the directory(c:\letters\temp) and open Word and separtly add each letter to the open session of Word. So inside of Word are 23 (letter01 - letter23) documents. The application just let the document get there. I'm try to come up with a macro to save all of the opened document within that session of Word. If you need more info let me know and I'll provide it to you. Thanks for all your help.

TonyJollans
08-11-2005, 04:27 PM
I'm confused - if you are asked for the path, I presume it's used and the only use I can see is to save the documents.

What is the dialog box you mentioned in your first post? I presume it says "Do you want to save changes" - if you answer "yes" do you get further prompts for the filename?

If the answer to the above is no (you get no further prompts), then you shouldn't need the code - just use the Save All option, and then close Word (it will close all the documents which you have already saved).

If the answer to the above is yes (you do get prompted) what prompt do you get?

espencer
08-12-2005, 05:01 AM
I made a mistake on this. It opens 23 sessions of Word and places each letter in each one. I would like to write a macro that will close all open session of Word. Sorry for the misunderstanding. Is this possible.

TonyJollans
08-12-2005, 06:16 AM
23 instances of Word? Are you quite sure? Whilst not impossible it would be a pretty odd application that did that.

Of course it would be possible to write some code to do something (although it might have some limitations) but I still need to know what use is made of the path that you choose within your application - are the documents saved to it (and then changed) so that a Save is all that is needed when you want to close, or are they not so that a Save As (requiring you to (re-)specify the path) is needed when you close - and if they are not created/saved by the application, what does it do with the path that you choose?

espencer
08-12-2005, 06:45 AM
The application give the user the option to the path. This path may have other documents from a previous run with the same name. I'm trying to figure a way for the user to create another folder to place new documents, right now most of the user don't change the path and the problem is that they are going to end up overlaying the old ones with the new ones. When they click on the X the standard dialog box pops up and i was wondering if I can bypass this with all opened WORD sessions.
Thanks again for all of your help.

MOS MASTER
08-12-2005, 02:16 PM
Hello,
I have an application that opens a session WORD and in the open session of WORD download 23 new word documents. Is there a way with a macro to save all 23 documents without clicking the X and reply to dialog box to save. This process takes too long to do. Any help would be much appreciated

Hi, :yes

You can use this Kb of mine:
http://www.vbaexpress.com/kb/getarticle.php?kb_id=488

This one closes all the documents without saving. (Also different instances)

To change it so it saves all documents you have to change the SaveChanges argument to the right saveoption.

In the code: SaveChanges:=wdDoNotSaveChanges is set which means the documents aren't saved.

You can change to: SaveChanges:=wdPromptToSaveChanges to get a prompt for each document if you want to save it.

But I think you just want to save the documents so change to:
SaveChanges:=wdSaveChanges

That will engage on saving each document. (Take special notice in the KB run global part to make sure it works correct)

HTH, :whistle:

espencer
08-15-2005, 05:46 AM
Thanks alot. This works great.

MOS MASTER
08-15-2005, 11:38 AM
You're welcome! :beerchug: