Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting ...

.... but I really want to solve this problem.

Sorry Halim it does not work.
Actually this code is opening a new instance of Word
but not the one wich is embedded in XL.

The problem is : if the user needs to modify the
text of the embedded Word, he first select the
Word object (right click) and then double click
on it.

This will open an instance of Word "inside" Excel.

This is this instance that would not terminate when
closing the workbook.

Thanks anyhow.

Patrick

"Halim" a écrit dans le message de news: ...
Place this code below in a standard module:
code below will open word better if you run 'Initial' once at first.
Public WordObj as Object
Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Then place code below in ThisWorkbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Thank you but I need further precisions.

The Word document is inbedded in a workbook
and programmatically I do not intent to act on it.

The user only opens the WB and modifies the
document if he needs and then closes the WB.

The WB is in another instance of Excel and saved
in the Before_Close sub.

Both the WB and the document have small pieces
of code mainly for design and behaviour.

So, at your idea, where should I put the code you
suggested ?

Thank you for answering.
Patrick

"Halim" a écrit dans le message de news:
...
hi,

You have to define your WORD object variable as a public variable

Public WordObj as Object

Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Hello Gurus,

I have a workbook which includes a Word document.

When, by VBA, the user quits this workbook, once the
Word document is edited, and returns into my app,
an instance of WINWORD is remaining active in the
tasks manager.

And more, even if the user leaves the application, this
WINWORD.EXE remains active and raises a problem
at the closing of Windows.

Any ideas, APIs, tips or tricks well accepted.
Many thanks.

Patrick







  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting ...

maybe you can do this but i'm not su
Sub CloseWord()
Set WordObj = getobject( , "word.application")
'do your stuff here...
WordObj.quit
End sub

Place that code after exiting word object
--
Regards,

Halim



"Patrick Penet" wrote:

.... but I really want to solve this problem.

Sorry Halim it does not work.
Actually this code is opening a new instance of Word
but not the one wich is embedded in XL.

The problem is : if the user needs to modify the
text of the embedded Word, he first select the
Word object (right click) and then double click
on it.

This will open an instance of Word "inside" Excel.

This is this instance that would not terminate when
closing the workbook.

Thanks anyhow.

Patrick

"Halim" a écrit dans le message de news: ...
Place this code below in a standard module:
code below will open word better if you run 'Initial' once at first.
Public WordObj as Object
Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Then place code below in ThisWorkbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Thank you but I need further precisions.

The Word document is inbedded in a workbook
and programmatically I do not intent to act on it.

The user only opens the WB and modifies the
document if he needs and then closes the WB.

The WB is in another instance of Excel and saved
in the Before_Close sub.

Both the WB and the document have small pieces
of code mainly for design and behaviour.

So, at your idea, where should I put the code you
suggested ?

Thank you for answering.
Patrick

"Halim" a écrit dans le message de news:
...
hi,

You have to define your WORD object variable as a public variable

Public WordObj as Object

Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Hello Gurus,

I have a workbook which includes a Word document.

When, by VBA, the user quits this workbook, once the
Word document is edited, and returns into my app,
an instance of WINWORD is remaining active in the
tasks manager.

And more, even if the user leaves the application, this
WINWORD.EXE remains active and raises a problem
at the closing of Windows.

Any ideas, APIs, tips or tricks well accepted.
Many thanks.

Patrick







  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting ...

No way !
This stupid WINWORD.EXE is still here.

I will search around for some APIs, I think I
remember one was doing the job.

Thanks anyway.

Patrick


"Halim" a écrit dans le message de news: ...
maybe you can do this but i'm not su
Sub CloseWord()
Set WordObj = getobject( , "word.application")
'do your stuff here...
WordObj.quit
End sub

Place that code after exiting word object
--
Regards,

Halim



"Patrick Penet" wrote:

.... but I really want to solve this problem.

Sorry Halim it does not work.
Actually this code is opening a new instance of Word
but not the one wich is embedded in XL.

The problem is : if the user needs to modify the
text of the embedded Word, he first select the
Word object (right click) and then double click
on it.

This will open an instance of Word "inside" Excel.

This is this instance that would not terminate when
closing the workbook.

Thanks anyhow.

Patrick

"Halim" a écrit dans le message de news:
...
Place this code below in a standard module:
code below will open word better if you run 'Initial' once at first.
Public WordObj as Object
Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Then place code below in ThisWorkbook module:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Thank you but I need further precisions.

The Word document is inbedded in a workbook
and programmatically I do not intent to act on it.

The user only opens the WB and modifies the
document if he needs and then closes the WB.

The WB is in another instance of Excel and saved
in the Before_Close sub.

Both the WB and the document have small pieces
of code mainly for design and behaviour.

So, at your idea, where should I put the code you
suggested ?

Thank you for answering.
Patrick

"Halim" a écrit dans le message de news:
...
hi,

You have to define your WORD object variable as a public variable

Public WordObj as Object

Sub Initial()
Set WordObj = createobject("word.application")
WordObj.visible = true
'do your stuff here...
End sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
WordObj.Quit
set WordObj = nothing
End Sub

--
Regards,

Halim



"Patrick Penet" wrote:

Hello Gurus,

I have a workbook which includes a Word document.

When, by VBA, the user quits this workbook, once the
Word document is edited, and returns into my app,
an instance of WINWORD is remaining active in the
tasks manager.

And more, even if the user leaves the application, this
WINWORD.EXE remains active and raises a problem
at the closing of Windows.

Any ideas, APIs, tips or tricks well accepted.
Many thanks.

Patrick









  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

"Patrick Penet" wrote:

No way !
This stupid WINWORD.EXE is still here.

I will search around for some APIs, I think I
remember one was doing the job.


Try this code to kill all WINWORD.EXE processes created by embedded objects:

Set objSWbem = CreateObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE' " & _
"And CommandLine Like '%-Embedding%'")

For Each objProcess In colProcesses
objProcess.Terminate
Next


--
urkec
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

I tried your code because it looks
quite new to me. (And I'm out of idea).

But can you indicate how I should define
theses variables objSWbem, colProcesses and
colProcesses.

I drove some tests at several places :

Public objSWbem As Object
Public colProcesses As Object
Public objProcess As Object

And also I defined them as variant.

But no chance : no errors at all, and the
!!%('$;!+) WINWORD.EXE is still there.

Thank you anyhow, and many thanks if
you follow this post.

Cordially.
Patrick


"urkec" a écrit dans le message de news: ...
"Patrick Penet" wrote:

No way !
This stupid WINWORD.EXE is still here.

I will search around for some APIs, I think I
remember one was doing the job.


Try this code to kill all WINWORD.EXE processes created by embedded objects:

Set objSWbem = CreateObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE' " & _
"And CommandLine Like '%-Embedding%'")

For Each objProcess In colProcesses
objProcess.Terminate
Next


--
urkec





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

"Patrick Penet" wrote:

I tried your code because it looks
quite new to me. (And I'm out of idea).

But can you indicate how I should define
theses variables objSWbem, colProcesses and
colProcesses.

I drove some tests at several places :

Public objSWbem As Object
Public colProcesses As Object
Public objProcess As Object

And also I defined them as variant.

But no chance : no errors at all, and the
!!%('$;!+) WINWORD.EXE is still there.





If I want to use early binding, I add reference to "Microsoft WMI Scripting
V2.1 Library". Where did you put the code? This code is supposed to kill all
WINWORD.EXE processes, does it work if you put it in a standard module and
run the sub manually with a WINWORD.EXE process running?


Sub WMITest()

Dim objSWbem As SWbemServices
Dim colProcesses As SWbemObjectSet
Dim objProcess As SWbemObject

Set objSWbem = GetObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE'")

For Each objProcess In colProcesses
Debug.Print objProcess.CommandLine
Debug.Print objProcess.ExecutablePath
objProcess.Terminate
Next

End Sub


Maybe you could also try using Shell function with Taskkill command. I am
not very good with Command Prompt, but I think that would be the simplest way
to kill a process.


--
urkec
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

If I want to use early binding, I add reference to "Microsoft WMI Scripting
V2.1 Library".


Yes, I understand your code. I am not used to program Microsoft WMI Scripting
Library because I am very much afraid it wont work with previous versions of
Windows.

Where did you put the code?
This code is supposed to kill all
WINWORD.EXE processes, does it work if you put it in a standard module and
run the sub manually with a WINWORD.EXE process running?


I tried the code in many different places, including a standard module
but it was with the 'embedded' parameter.

Your code below is perfectly swell and works fine with a normal
Word session, but not with the embedded one.

Sub WMITest()
Dim objSWbem As SWbemServices
Dim colProcesses As SWbemObjectSet
Dim objProcess As SWbemObject


Set objSWbem = GetObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE'")
For Each objProcess In colProcesses
Debug.Print objProcess.CommandLine
Debug.Print objProcess.ExecutablePath
objProcess.Terminate
Next
End Sub


Maybe you could also try using Shell function with Taskkill command. I am
not very good with Command Prompt, but I think that would be the simplest way
to kill a process.
--
urkec


By the way, I thank you very much for these pieces of code that
I will keep in pocket for future needs.

Regards.
Patrick


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

"Patrick Penet" wrote:

If I want to use early binding, I add reference to "Microsoft WMI Scripting
V2.1 Library".


Yes, I understand your code. I am not used to program Microsoft WMI Scripting
Library because I am very much afraid it wont work with previous versions of
Windows.

Where did you put the code?
This code is supposed to kill all
WINWORD.EXE processes, does it work if you put it in a standard module and
run the sub manually with a WINWORD.EXE process running?


I tried the code in many different places, including a standard module
but it was with the 'embedded' parameter.

Your code below is perfectly swell and works fine with a normal
Word session, but not with the embedded one.

Sub WMITest()
Dim objSWbem As SWbemServices
Dim colProcesses As SWbemObjectSet
Dim objProcess As SWbemObject


Set objSWbem = GetObject("winmgmts:root\cimv2")
Set colProcesses = objSWbem.ExecQuery _
("Select * From Win32_Process " & _
"Where Name='WINWORD.EXE'")
For Each objProcess In colProcesses
Debug.Print objProcess.CommandLine
Debug.Print objProcess.ExecutablePath
objProcess.Terminate
Next
End Sub


Maybe you could also try using Shell function with Taskkill command. I am
not very good with Command Prompt, but I think that would be the simplest way
to kill a process.
--
urkec


By the way, I thank you very much for these pieces of code that
I will keep in pocket for future needs.

Regards.
Patrick





I used WMI with Windows 2000 and WIndows XP, mostly to get system
information I couldn't get some other way (Documentation says WMI is
available for Windows 2000, Windows XP, and Windows Me). Other than
compatibility, problems could be that user needs administrator privileges tor
run it and that some classes are only available with XP, etc.
I tested the code to terminate WINWORD.EXE a couple of times and it seemed
to work with with processes created by embedded objects. Sorry it didn't work
for you, I hope you find some other solution.


--
urkec
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Cannot kill a WINWORD.EXE instanciation - Sorry for reposting

Thank you for these interesting precisions.
Regards

Patrick


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot kill a WINWORD.EXE instanciation Patrick Penet Excel Programming 9 March 12th 08 03:45 AM
Closing WINWORD.EXE from Excel VBA when my main proc ends Edmund Excel Programming 2 August 22nd 07 03:09 AM
Paste in WinWord, problems with several processes lasse g Excel Programming 2 March 3rd 05 03:37 PM
Open Winword from Excel Robert Christie[_3_] Excel Programming 2 February 14th 04 04:27 AM
Open Winword-file using a Excel 97 VBA macro Dominik Scheck Excel Programming 4 August 5th 03 02:35 AM


All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"