Home All Groups Group Topic Archive Search About

Application.Quit but Word remains open in Task Manager

Author
15 Mar 2009 9:17 PM
Simon Keeling
Hello,

I have writtwen the following routine, but depsite Word closing it
remains open in the Task Manager, and so when AutoExec fires again it
will not run befcuase Word is open elsewhere.

Is there code that I can use which will truly quite and close Word?

Thanks in advance,
Simon
England.


Sub allwingriddsprepare()
wingriddsprepare00
wingriddsprepare06
wingriddsprepare12
wingriddsprepare18
Application.Quit

End Sub

Author
15 Mar 2009 10:22 PM
Bill McCarthy
Hi simon,

Is this VB6 code or VBA ?  If the later then I doubt you can kill the app as
your code is being launched by it.  If VB6, where is "Application" defined ?


Show quoteHide quote
"Simon Keeling" <si***@weatherweb.net> wrote in message
news:5c4e15cf-efdb-4548-8039-e8b5217f226e@j35g2000yqh.googlegroups.com...
> Hello,
>
> I have writtwen the following routine, but depsite Word closing it
> remains open in the Task Manager, and so when AutoExec fires again it
> will not run befcuase Word is open elsewhere.
>
> Is there code that I can use which will truly quite and close Word?
>
> Thanks in advance,
> Simon
> England.
>
>
> Sub allwingriddsprepare()
> wingriddsprepare00
> wingriddsprepare06
> wingriddsprepare12
> wingriddsprepare18
> Application.Quit
>
> End Sub
Author
16 Mar 2009 11:36 AM
Peter T
"Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message

> Is this VB6 code or VBA ?  If the later then I doubt you can kill the app
> as your code is being launched by it.

Actually VBA in Office app's can quit itself, both as a project and it's
host application. Of course there might be other objects hanging around that
might prevent the close and/or quit. In the case of Word even some open
unsaved Outlook mailItem.

The OP's code sample is possibly the most unhelpful I have ever seen :-)

Regards,
Peter T
Author
16 Mar 2009 1:49 PM
Simon Keeling
Thanks for that Peter, so it could be something else open? I will have
a look and see what I can find.

Soprry about the code, but that is all I have as that is the routing.
What else would you have liked to have seen?

Thanks,
Simon


Show quoteHide quote
On Mar 16, 11:36 am, "Peter T" <peter_t@discussions> wrote:
> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>
> > Is this VB6 code or VBA ?  If the later then I doubt you can kill the app
> > as your code is being launched by it.
>
> Actually VBA in Office app's can quit itself, both as a project and it's
> host application. Of course there might be other objects hanging around that
> might prevent the close and/or quit. In the case of Word even some open
> unsaved Outlook mailItem.
>
> The OP's code sample is possibly the most unhelpful I have ever seen :-)
>
> Regards,
> Peter T
Author
16 Mar 2009 4:41 PM
Peter T
Apart from the app.quit line your code does not tell us anything at all. Not
even which application it runs in though presumably it's Word VBA in a word
document.

What's wingriddsprepare00 and the others? some routines, what do they do,
what else is going on, etc, etc, and not least where is the code.

If indeed it is Word ask in one of the Word groups, eg
microsoft.public.word.vba.general
(this group is not VBA)

However you will need to give some information beyond "my car doesn't work
what's wrong".

Regards,
Peter T


"Simon Keeling" <si***@weatherweb.net> wrote in message
news:b8f30bb1-2f87-4f47-903c-c26bbbd221ad@v19g2000yqn.googlegroups.com...
Thanks for that Peter, so it could be something else open? I will have
a look and see what I can find.

Soprry about the code, but that is all I have as that is the routing.
What else would you have liked to have seen?

Thanks,
Simon


Show quoteHide quote
On Mar 16, 11:36 am, "Peter T" <peter_t@discussions> wrote:
> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>
> > Is this VB6 code or VBA ? If the later then I doubt you can kill the app
> > as your code is being launched by it.
>
> Actually VBA in Office app's can quit itself, both as a project and it's
> host application. Of course there might be other objects hanging around
> that
> might prevent the close and/or quit. In the case of Word even some open
> unsaved Outlook mailItem.
>
> The OP's code sample is possibly the most unhelpful I have ever seen :-)
>
> Regards,
> Peter T
Author
16 Mar 2009 3:19 PM
Bill McCarthy
Hi Peter,

"Peter T" <peter_t@discussions> wrote in message
news:ee4WjtipJHA.3840@TK2MSFTNGP03.phx.gbl...
>
> "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>
>> Is this VB6 code or VBA ?  If the later then I doubt you can kill the app
>> as your code is being launched by it.
>
> Actually VBA in Office app's can quit itself, both as a project and it's
> host application.


Thanks, but if he did that, then no subsequent code would run.

BTW: Does Application.Quit kill all instances ? I would presume only the one
it is running in.


> Of course there might be other objects hanging around that might prevent
> the close and/or quit. In the case of Word even some open unsaved Outlook
> mailItem.
>

Yep, this is the most likely cause.


> The OP's code sample is possibly the most unhelpful I have ever seen :-)
>

More information is needed, but it does look to me like it was/is VBA, not
VB.
Author
16 Mar 2009 4:27 PM
Simon Keeling
Dear all,

Looks like you have solved it for me. I have closed Outlook and run
the procedure again. Word closed!

Thanks,
Simon

Show quoteHide quote
On Mar 16, 3:19 pm, "Bill McCarthy" <TPASoft.com Are Identity Thieves>
wrote:
> Hi Peter,
>
> "Peter T" <peter_t@discussions> wrote in message
>
> news:ee4WjtipJHA.3840@TK2MSFTNGP03.phx.gbl...
>
>
>
> > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>
> >> Is this VB6 code or VBA ?  If the later then I doubt you can kill the app
> >> as your code is being launched by it.
>
> > Actually VBA in Office app's can quit itself, both as a project and it's
> > host application.
>
> Thanks, but if he did that, then no subsequent code would run.
>
> BTW: Does Application.Quit kill all instances ? I would presume only the one
> it is running in.
>
> > Of course there might be other objects hanging around that might prevent
> > the close and/or quit. In the case of Word even some open unsaved Outlook
> > mailItem.
>
> Yep, this is the most likely cause.
>
> > The OP's code sample is possibly the most unhelpful I have ever seen :-)
>
> More information is needed, but it does look to me like it was/is VBA, not
> VB.
Author
16 Mar 2009 5:05 PM
Peter T
Well that was a wild guess earlier, probably not necessary to close Outlook
entirely, just mail items.

Strange, I didn't see this your latest post "sent" a while before my other
two recent posts.

Regards,
Peter T


"Simon Keeling" <si***@weatherweb.net> wrote in message
news:96ab0917-c16a-4bc8-959a-fa101d5611cc@v38g2000yqb.googlegroups.com...
Dear all,

Looks like you have solved it for me. I have closed Outlook and run
the procedure again. Word closed!

Thanks,
Simon

Show quoteHide quote
On Mar 16, 3:19 pm, "Bill McCarthy" <TPASoft.com Are Identity Thieves>
wrote:
> Hi Peter,
>
> "Peter T" <peter_t@discussions> wrote in message
>
> news:ee4WjtipJHA.3840@TK2MSFTNGP03.phx.gbl...
>
>
>
> > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message
>
> >> Is this VB6 code or VBA ? If the later then I doubt you can kill the
> >> app
> >> as your code is being launched by it.
>
> > Actually VBA in Office app's can quit itself, both as a project and it's
> > host application.
>
> Thanks, but if he did that, then no subsequent code would run.
>
> BTW: Does Application.Quit kill all instances ? I would presume only the
> one
> it is running in.
>
> > Of course there might be other objects hanging around that might prevent
> > the close and/or quit. In the case of Word even some open unsaved
> > Outlook
> > mailItem.
>
> Yep, this is the most likely cause.
>
> > The OP's code sample is possibly the most unhelpful I have ever seen :-)
>
> More information is needed, but it does look to me like it was/is VBA, not
> VB.
Author
16 Mar 2009 4:52 PM
Peter T
Hi Bill,

>> Actually VBA in Office app's can quit itself, both as a project and it's
>> host application.
>
>
> Thanks, but if he did that, then no subsequent code would run.

Could struggle on for a while, a bit like this in a form

Private Sub Command1_Click()
Unload Me
MsgBox "still hanging in there"
End Sub

Actually I've never quite understood how that works.

> BTW: Does Application.Quit kill all instances ? I would presume only the
> one it is running in.

Could do objApp.Quit to kill any referenced instance, subject released
objects, or dialogs appearing (eg the save prompt or some other warning in a
hidden instance).

'Application' in VBA only refers to the single instance hosting that code.

Regards,
Peter T
Author
17 Mar 2009 7:01 AM
Eduardo
"Peter T" <peter_t@discussions> escribió en el mensaje
news:O84%23celpJHA.1172@TK2MSFTNGP05.phx.gbl...

> Could struggle on for a while, a bit like this in a form
>
> Private Sub Command1_Click()
> Unload Me
> MsgBox "still hanging in there"
> End Sub
>
> Actually I've never quite understood how that works.

Because the code module is separate from the form object (I don't understand
the details, this is as much - I think.- I undestand).

Try this:

Start a new project, add another form (Form2) and a command button to each
form.

' Form1 code:

Private Sub Command1_Click()
    Form2.pVar = 5
    Form2.Show 1
    MsgBox Form2.pVar
End Sub

' Form2 code:

Public pVar As Long

Private Sub Command1_Click()
    Unload Me
End Sub

You can see that the variable still holds the value after the form is
unloaded.
To completely erase the form, you need to set it to nothing:

' Modify Form1 code to:

Private Sub Command1_Click()
    Form2.pVar = 5
    Form2.Show 1
    MsgBox Form2.pVar
    Set Form2 = Nothing
    MsgBox Form2.pVar
End Sub

You also can set the form to nothing from within the form itself, but as it
is still executing code, it does it after it is unloaded.

' Modify Form2 code to:

Public pVar As Long

Private Sub Command1_Click()
    Unload Me
    Set Form2 = Nothing
    MsgBox "from Form2: " & pVar
End Sub
Author
17 Mar 2009 11:41 AM
Peter T
"Eduardo" <m*@mm.com> wrote in message news:gpnhs4$5bs$1@aioe.org...

> To completely erase the form, you need to set it to nothing:

Yes, my example was not a good one with only the Unload

> You also can set the form to nothing from within the form itself, but as
> it is still executing code, it does it after it is unloaded.
>
> ' Modify Form2 code to:
>
> Public pVar As Long
>
> Private Sub Command1_Click()
>    Unload Me
>    Set Form2 = Nothing
>    MsgBox "from Form2: " & pVar
> End Sub

This better illustrates what I meant, the terminate event will not fire
until all code has completed. It is similar with code in VBA that does
meProject.Close or Application.Quit. It seems these types of instructions
are not executed linearly but put on hold or set aside until all other code
completes.

In some VBA app's any routine can be called immediately after all other
running code completes with the OnTime function, seems like these Set
me=nothing, .close & .quit functions work similarly, I guess.

Regards,
Peter T
Author
19 Mar 2009 12:46 AM
Bill McCarthy
Show quote Hide quote
"Peter T" <peter_t@discussions> wrote in message
news:O84%23celpJHA.1172@TK2MSFTNGP05.phx.gbl...
> Hi Bill,
>
>>> Actually VBA in Office app's can quit itself, both as a project and it's
>>> host application.
>>
>>
>> Thanks, but if he did that, then no subsequent code would run.
>
> Could struggle on for a while, a bit like this in a form
>
> Private Sub Command1_Click()
> Unload Me
> MsgBox "still hanging in there"
> End Sub
>
> Actually I've never quite understood how that works.
>

If you think of the form as a class, the load/unload merely the create and
destroy windows part there-of.


>> BTW: Does Application.Quit kill all instances ? I would presume only the
>> one it is running in.
>
> Could do objApp.Quit to kill any referenced instance, subject released
> objects, or dialogs appearing (eg the save prompt or some other warning in
> a hidden instance).
>
> 'Application' in VBA only refers to the single instance hosting that code.
>

Thanks.