PDA

View Full Version : CLOSING MULTIPLE OPEN WORD DOCS



timetunnel
01-27-2007, 11:12 PM
Hello everyone:

My scenario:

Thanks to all the help I've received I've been able to piece together a "control module" (a UserForm in a template for a report generation system. 1 of my "menu options" (OptionButtons) - we'll call this OPTION 1, opens up 2 additional word docs (actually templates - .dot). These will be massaged and then I want to just flat save them with their original names into their original directories and I want to do this with another OptionButton on my UserForm (menu).

There is another OptionButton which opens another template which has another menu which allows users to reopen the 2 previously mentioned files and merge them into the new blank doc. This probably sounds overly complicated, but there were some good reasons to cascade these template/menu control modules.

Anyway, this is all working except for the fact that my OPTION 1 ( see above) blows up. The files really are open, but I have to click on WINDOW to go to them.

So to recap, I simply want to close the 2 files I opened from my menu, with another menu option and I want the template that is controlling the meun to remain open. I'm hoping this is as simple as it seems, although I've hacked around for a good while and can't make anything work, nor did I find anything on the forum.

Hope someone has seen this before.

Regards to all!

Bob Phillips
01-28-2007, 04:29 AM
If you know the names of the files, can't you just issue a close statement?



documents("document name.dot").Close savechanges:=false

timetunnel
01-28-2007, 11:46 AM
Thanks xld!
One certainly can save them that way if one isn't an idiot!

I was trying to use:
wrd.Document.SaveAs "C:\fold\BASETAS.dot"
I was actually thinking Word was smart enough to figure out what file I was referring to! :help

In your method "Documents("BASEDSTM.dot").Close savechanges:=False"
I set the save to True. Is there a way to modify it to include a path? Although I want to save the files in the original folders, there will come a time when I will want to do otherwise.

Anyway, thanks for the help - A G A I N!!!

Regards...

Bob Phillips
01-28-2007, 12:43 PM
No, assuming you wan t to save the document to a different folder (else why not just Save), you save it with a path, then close it.



With Documents("BASEDSTM.dot")
.SaveAs "C:\fold\BASEDSTM.dot"
.Close
End With

timetunnel
01-28-2007, 12:59 PM
OK, I see the dif in what you're saying and what I was trying to do. My original attempt was:

wrd.Document.SaveAs "C:\fold\BASETAS.dot"

Which didn't work due to the fact that multiple files were open and word couldn't "get" there.

Your modified version:
With Documents("BASEDSTM.dot")
.SaveAs "C:\fold\BASEDSTM.dot"
.Close
End With

Contains a WITH, which I assume brings some different operators into play.

Anyway,

THANKS 33 TERABYTES WORTH!

Regards...

Bob Phillips
01-28-2007, 04:27 PM
Not really, that code is the same as



Documents("BASEDSTM.dot").SaveAs "C:\fold\BASEDSTM.dot"
Documents("BASEDSTM.dot").Close

By using With, I am avoiding the need to explicitly declare the parent object each time, making the code easier to read, but more importantly, saving VBA the need to resolve that object qualification each time.

timetunnel
01-28-2007, 07:32 PM
Yeah, I see:

Sans the technical efficiency of With, your code:
With Documents("BASEDSTM.dot")
.SaveAs "C:\fold\BASEDSTM.dot"
.Close
End With

timetunnel
01-28-2007, 07:32 PM
Yeah, I see:

Sans the technical efficiency of With, your code:
With Documents("BASEDSTM.dot")
.SaveAs "C:\fold\BASEDSTM.dot"
.Close
End With

differs from mine:
wrd.Document.SaveAs "C:\fold\BASETAS.dot"

timetunnel
01-28-2007, 07:37 PM
Yeah, I see:

Sans the technical efficiency of With, your code:
With Documents("BASEDSTM.dot")
.SaveAs "C:\fold\BASEDSTM.dot"
.Close
End With

differs from mine:
wrd.Document.SaveAs "C:\fold\BASETAS.dot"
in that you first point to the file and then save it where I only attempted the save. With multiple files open it's like "save what"!

I appreciate your help!!!