Closing current instance of Word 2003

P

Paul B

Hi,

I'm trying to close the current instance of Word 03 without affecting any
other open instances.

So far I've got

ActiveDocument.Close savechanges:=wdSaveChanges

but that only closes the document, leaving the application window still
open.

Obviously I have Word set to the (more or less) equivalent of classic MDI,
each instance in its own window.

Any help would be appreciated.

Thanks and BW,
p.
 
P

Perry

Obviously I have Word set to the (more or less) equivalent of classic MDI,
each instance in its own window.

If you´ve coded correctly, you can quit each object variable pointing to a
newly created
Word instance seperately.

This is a sequence within Word VBA (!) examplifying object orientated coding
in which
each instance can be addressed seperately and in yr case: killed seperately:
(actually a bit of "inter appliation" automation ... oops that didn't sound
too good, now did it? ....)

Dim Inst1 As New Word.Application
Dim Inst2 As New Word.Application
Dim Doc1 As Document
Dim Doc2 As Document

Inst1.Visible = True
Inst2.Visible = True

Set Doc1 = Inst1.Documents.Add
Set Doc2 = Inst2.Documents.Add

Doc1.Windows(1).Visible = True
Doc2.Windows(1).Visible = True

Doc1.Range(0, 0).InsertAfter "text in doc1"
Doc2.Range(0, 0).InsertAfter "text in doc2"

Doc1.Close 0
Inst1.Quit: Set Inst1 = Nothing

'Now all actions of Inst1 are processed, leaving you Inst2 with document and
the text to proof this.
' Note: all other previsouly instances of Word should be intact as well !

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
P

Paul B

If you´ve coded correctly, you can quit each object variable pointing to a
newly created
Word instance seperately.

This is a sequence within Word VBA (!) examplifying object orientated coding
in which
each instance can be addressed seperately and in yr case: killed seperately:
(actually a bit of "inter appliation" automation ... oops that didn't sound
too good, now did it? ....)

Dim Inst1 As New Word.Application
Dim Inst2 As New Word.Application
Dim Doc1 As Document
Dim Doc2 As Document

Inst1.Visible = True
Inst2.Visible = True

Set Doc1 = Inst1.Documents.Add
Set Doc2 = Inst2.Documents.Add

Doc1.Windows(1).Visible = True
Doc2.Windows(1).Visible = True

Doc1.Range(0, 0).InsertAfter "text in doc1"
Doc2.Range(0, 0).InsertAfter "text in doc2"

Doc1.Close 0
Inst1.Quit: Set Inst1 = Nothing

'Now all actions of Inst1 are processed, leaving you Inst2 with document and
the text to proof this.
' Note: all other previsouly instances of Word should be intact as well !


Thanks, Perry. Definitely a keeper for its depth of insight.

I thought I figured out an easy way to do what I need via SendKeys:

Sub SaveClose()
' Save and Close doc NOW; 03/10/07
ActiveDocument.Close savechanges:=wdSaveChanges
SendKeys "%{f4}"
End Sub

However I then noticed a strange side effect - executing the macro turns
off NumLock! Bizarre.

I'll try later to see if I can salvage my idea or incorporate yours.

Thanks and BW,
p.
 
T

Tony Jollans

I believe ...

Application.Quit

... is probably the line of code you are looking for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top