.ActiveDocument.Close

K

kirkm

As .ActiveDocument.Close
executes the document closes but at the same time a new Word
icon appears in the task bar.

Can this be closed in VB please ?
 
J

Jonathan West

kirkm said:
As .ActiveDocument.Close
executes the document closes but at the same time a new Word
icon appears in the task bar.

Can this be closed in VB please ?

If you want to close Word altogether, use the Application.Quit method.
 
K

kirkm

If you want to close Word altogether, use the Application.Quit method.

That closes Word and leaves my Document in the task bar. I'd hoped to
close the Document but leave Word open to process the next one.

The line that opens it is

Dim OpenWord As Word.Application
Set OpenWord = New Word.Application

Then
..Documents.Open sDoc, , True

When sDoc is closed (I've tried every which way & method I know) it
leaves a Word Icon in the task bar. This happens every time
sDoc is closed. There's several hundred of them, so to run the batch
I'd like to kill this icon.

Can anyone help?

Thanks - Kirk
 
C

Curt

Have this in my macro it does not exit word at end what am I missing. Blinded
Thanks
ActiveWindow.Close
ActiveDocument.Close wdDoNotSaveChanges
Application.Quit
 
J

Jonathan West

Curt said:
Have this in my macro it does not exit word at end what am I missing.
Blinded
Thanks
ActiveWindow.Close
ActiveDocument.Close wdDoNotSaveChanges
Application.Quit

Are you controlling Word from an external VB program? If so, can you show is
the code that is sets up the link to Word?
 
C

Curt

Hope this will give you what you need. I should add I end up with the print
screen that you have to close or cancel I close the print screen then I get a
brown word screen. Closeing this I then go back to the userform I started
from.
Thanks
Private Sub OptionButton1_Click()
'Printing Entry Letters
OptionButton1.Value = False
UserForm4_Letters.Hide
Sheets("MailE").Select
Dim word As New word.Application
Dim wordDoc As word.Document
word.Visible = True
Set wordDoc = word.Documents.Open("C:\Parade\Letter.doc")
With wordDoc
..Application.Run "macro1"--This is the word macro
End With
End sub
 
C

Curt

After thought this is the last part of the word macro maybe the problem is
here? This was all built with macro recorder in word.
Thanks again
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Destination = wdSendToPrinter
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = False
With .datasource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
'ActiveWindow.Close
ActiveDocument.Close wdDoNotSaveChanges
Application.Quit
ActiveWindow.Close
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
If Documents.count <= 0 Then Application.Quit
End Sub
 
K

kirkm

Thanks Curt & Jonathan,

I'm not much further ahead and having some trouble applying Curts
suggestion.

Maybe I could explain step by step what I'm doing and it may
demonstrate the problem.

I Double click Doc1.doc and when it opens I hit Alt F11 and get to the
code window. Which has :-

--
Sub testdoc()
Dim OpenWord As Word.Application
Set OpenWord = New Word.Application
Dim D As Document
Dim LastLine%, i%
Dim R As Range
With OpenWord
.Visible = True
.Documents.Open "O:\test.html", , True
Set D = .ActiveDocument
LastLine = D.Paragraphs.Count
For i = 1 To LastLine ' or less while playing
DoEvents
Set R = D.Paragraphs(i).Range
Debug.Print R
Next i
..Documents.Close
'ActiveDocument.Close wdDoNotSaveChanges
End With
Set OpenWord = Nothing
End Sub
--

(When working properly I'd send in the filename and do more stuff in
the i For Next loop.)

The command .Documents.Close closes test.html but leaves an instance
of Word (the second one?) open. I need to close this or you get a new
one for every file processed. My problem is closing it.

If I unrem the 'ActiveDocument.Close line this closes doc1.doc then
leaves TWO Words open.

Sorry I can't explain this any better as it must be quite simple..
Possibly I'm closing the file OK but stlll need to close Word - but
not the Word running Doc1.doc.

Thanks - Kirk
 
C

Curt

I have tried all I can think of to get a close from the print screen & word
to return to my user form. Theres got to be an answer some where.
Blinded
 
J

Jonathan West

Hi Curt

OK, i think I see the problem.


1. Don't use "Dim word As New word.Application"
Also, I would put a prefix on "word" so that it can't possibly be confused
with a part of the object model. Instead, separate out the declaraction an
assignment lines like this

Dim oWord as Word.Application
Set oWord = New Word.Application.

2. If you want to use that specific instance of Word in seveal different
routines, you need to declare oWord as a Public variable outside any
routine, by using the following at the top of the Form module

Private oWord as Word.Application

or if Word is being referred to by code from outside the form, like this

Public oWord as Word.Application

3. Once you have initialised the oWord variable, you must use it as the
prefix in *every* line of code that controls the Word object model.

At the moment, you are declaring a new instance of Word every time you click
OptionButton1, not ensuring that the object prefix is used, and referencing
the word object model elsewhere without making it clear which instance of
Word you are using.
 
C

Curt

it took me a long time to find solution for mine it was location of code lines
..Execute Pause:=True
Application.Quit SaveChanges:=wdDoNotSaveChanges
End With
Hope this will help you
 
C

Curt

Want to thank you for your direction. Also I located my error in location of
code. Got everything working now.
Thanks Again
 

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