|
-
Jul 22nd, 2007, 08:50 AM
#1
Thread Starter
Junior Member
Track "WINWORD.EXE" VB6
Hi everyone,
I have a case where there will be multiple "WINWORD.EXE" instances running at the same time in Task Manager. Each "WINWORD.EXE' might be controlling one Word document or a few Word documents or even none.
(1) My question is, is there anyway to track like which "WINWORD.EXE" is controlling which Word Document(s). I want to do it programatically in VB.
(2) And also, is there anyway to track any hanging "WINWORD.EXE"? As i can see sometime "WINWORD.EXE" is not close even though you close the word document. I want to do it programatically in VB.
Help PLEASEE... Thanks..
-
Jul 22nd, 2007, 10:56 AM
#2
Re: Track "WINWORD.EXE" VB6
 Originally Posted by JCheah
Hi everyone,
I have a case where there will be multiple "WINWORD.EXE" instances running at the same time in Task Manager. Each "WINWORD.EXE' might be controlling one Word document or a few Word documents or even none.
I have opened 2 seperate word documents and i see brought controlled by a single WINWORD.EXE with same process id, How did you get that multiple WINWORD.EXE ?
-
Jul 22nd, 2007, 11:07 AM
#3
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Because i'm using CreateObject function to create multiple "WINWORD.EXE" instance. I need multiple instances to control those word document separately.
Actually my main point here is I'm looking for a way to close those hanging "WINWORD.EXE" which are no longer in use and remain those 'IN USE" WINWORD.EXE. That's why i need to find a way to track those IN USE instances.
Thanks..
-
Jul 22nd, 2007, 11:15 AM
#4
Re: Track "WINWORD.EXE" VB6
Accordin to my knowledge, you will need to enumurate all the windows that have a trailing window text ' - Microsoft Word'. you can use EnumWindows() fro this. Then find the one with the window text 'Not Responding'. use GetWindowThreadProcessId () to obtain the process id of that window. kill it !!
-
Jul 22nd, 2007, 11:32 AM
#5
Re: Track "WINWORD.EXE" VB6
The main reason for Office applications 'hanging' when being used from a VB program is, unfortunately, bad code in your VB program. For some reason it seems to work (even tho it is technically not valid code), and then issues like this occur.
Rather than trying to auto-close Word (and perhaps corrupt files etc), you should try to fix your code instead.. if you show us what code you are using, we can help you do that.
-
Jul 22nd, 2007, 12:07 PM
#6
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Hi guys,
Actually I'm currently using Word 2003 and Win XP. The reason why i have multiple WINWORD.EXE instances under the "Processes" in Task Manager is because I'm using the CreateObject function to create new instance for each word document being opened. I inserted the CreateObject function code under the "Normal.dot" each time my VB6 program runs and delete the code from the word template after that. Therefore, each time the user open any Word Document, a new instance "WINWORD.EXE" will be created.
The reason why i'm doing this is because my program will be processing a selected word document, if the user open any other word document in the middle of myu program processing, a new Word instacen will be created. So, these word docs will be operated under different instances, and won't mess up with each other. As i don't want my program mistakenly jumps to process the other word document.
But the problem with this approach is sometimes it creates too many intances at the end of my program processing, Therefore I'm looking for a way to close those hanging "WINWORD.EXE" which are no longer in use at the end of processing and remain those WINWORD.EXE which are still IN USE by the users. That's why i need to find a way to track those IN USE instances.
Please advise...
-
Jul 22nd, 2007, 12:22 PM
#7
Re: Track "WINWORD.EXE" VB6
Ok, I think this part of your post tells me your actual problem:
So, these word docs will be operated under different instances, and won't mess up with each other. As i don't want my program mistakenly jumps to process the other word document.
Unless there is (poor) code running, documents will have no effect on each other.
It sounds to me as if you are doing something that too many people do (as it is how auto-generated macros, and too many examples, are written), which is using code that specifically works with Active or Selected items, rather than actually specifying the items you want to work with.
If you show us some of your code, we can suggest safer ways of writing the same code (so that they actually refer to the document you want, rather than whichever is currently 'in use').
-
Jul 22nd, 2007, 12:41 PM
#8
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Hi Geek,
Yeah, actually i did receive some responses from other forum about the problem of Selection or ActiveWindow VBA code too. And they advised me to use Range object. But i found out the Range object doesn't show me the same properties as Selection. And i couldn't get any further helps on this.
Anyway, the following is small part of my code. basically the following procedure is doing some find and replace in a word document. See if you could help me to convert the following part into the "safer" code as you mentioned. You help will be greatly appreciated. Thanks.
Code:
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim formName as String
Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdfileM.Documents.Open(filePath)
With wrdApp.Application
'this part of code is getting the certain words from the document header
If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
.ActiveWindow.Panes(2).Close
End If
If .ActiveWindow.ActivePane.View.Type = wdNormalView Or .ActiveWindow.ActivePane.View.Type = wdOutlineView Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.MoveRight unit:=wdCell
.Selection.MoveRight unit:=wdCharacter, Count:=2, Extend:=wdExtend
formName = .Selection.Text
.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
'----------------------------------------------------------------------------------------------------------------
'*#1 Find and Replacement Procedure (Mark Heading)
'----------------------------------------------------------------------------------------------------------------
.Selection.HomeKey unit:=wdStory
'set the find criteria based on the following font and paragraph format
.Selection.Find.ClearFormatting
With .Selection.Find.Font
.Size = 10
.Bold = True
End With
With .Selection.Find.ParagraphFormat
.SpaceBeforeAuto = False
.SpaceAfterAuto = False
.Alignment = wdAlignParagraphLeft
End With
'Selection.Find.Style = ActiveDocument.Styles("outlinehd1")
'set the replacement criteria where all the matches will be replaced with an empty space character
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find.Replacement.Font
.Underline = wdUnderlineDouble
.UnderlineColor = wdColorAutomatic
.Strikethrough = True
End With
'execute the find and replacement
.Selection.Find.Execute Replace:=wdReplaceAll
.Selection.Goto What:=wdGoToPage, Which:=wdGoToNext, Name:=2
End With
Last edited by RobDog888; Jul 22nd, 2007 at 01:53 PM.
Reason: added [code] tags
-
Jul 22nd, 2007, 01:55 PM
#9
Re: Track "WINWORD.EXE" VB6
What is it that you are missing from the range object thats not in the selection object? The selection object is also a Range. 
.Selection.Find
equilivalent...
ThisDocument.Range.Find
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 22nd, 2007, 02:05 PM
#10
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Hi RobDog888,
How about the following part? I got the following code form the Word macro. Bascially the following code is going to get certain text from the Header of Document. Can you convert? Thanks..
'this part of code is getting the certain words from the document header
If .ActiveWindow.View.SplitSpecial <> wdPaneNone Then
.ActiveWindow.Panes(2).Close
End If
If .ActiveWindow.ActivePane.View.Type = wdNormalView Or .ActiveWindow.ActivePane.View.Type = wdOutlineView Then
.ActiveWindow.ActivePane.View.Type = wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
.Selection.MoveRight unit:=wdCell
.Selection.MoveRight unit:=wdCharacter, Count:=2, Extend:=wdExtend
-
Jul 22nd, 2007, 02:21 PM
#11
Re: Track "WINWORD.EXE" VB6
Code:
If ThisDocument.Windows.Item(1).View.SplitSpecial <> wdPaneNone Then
You get the idea now.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 22nd, 2007, 02:36 PM
#12
Re: Track "WINWORD.EXE" VB6
Also, it is possible to just read the header directly, eg:
Code:
formName = wrdDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text
..however, this is less generic than the code you currently have (which will read the header for the current page), and so it may need to be modified if your document has multiple Sections (groups of pages) or multiple headers (eg: different headers for odd & even pages).
Even tho what I have posted is shorter, it would need modifications to work in all situations - so I would recommend changing what you have, using the method that Robdog suggested.
Note that a major issue with your code is the line "With wrdApp.Application", partly because wrdApp is the application (thus the .Application on the end is superfluous), but mainly because it means that all of your code deals with the application (thus whichever document it likes) rather than the specific document you want (wrdDoc).
Changing it to "With wrdDoc" should reduce the problems, but you may find that it means you need to make minor modifications to some of your other code.
-
Jul 22nd, 2007, 03:10 PM
#13
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Hi RobDog888 & Geek,
I'm kind of seeing the light now...
Anyway, still please kindly verify the following
(1) How about the following movement part. Sometimes i move the cursor to right, left, up down in the document. And sometimes I move my cursor to the end of a sentence to select the entire sentence.
.Selection.MoveRight unit:=wdCell
.Selection.MoveUp unit:=wdLine
.Selection.MoveLeft unit:=wdCharacter, Count:=2, Extend:=wdExtend
.Selection.MoveRight unit:=wdSentence, Count:=1, Extend:=wdExtend
(2) if i want to refer to certain selection in the word document, can I use "ThisDocument.Range" instead of ".Selection"?
Thanks for your great great help...
-
Jul 22nd, 2007, 03:48 PM
#14
Re: Track "WINWORD.EXE" VB6
ThisDocument.Range is encmpassing the entire document as the range whereas the seletion.range is only taking the selected part as the range. So be careful in translating macros with that.
Again, whatever the range you can move within it.
Code:
Set oRange = ThisDocument.Paragraphs(1).Range
With oRange
.Move Unit:=wdParagraph, Count:=3
End With
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 22nd, 2007, 05:24 PM
#15
Thread Starter
Junior Member
Re: Track "WINWORD.EXE" VB6
Hi RobDog888,
Millions thanks...you are always so helpful..
-
Jul 22nd, 2007, 05:27 PM
#16
Re: Track "WINWORD.EXE" VB6
Was just thinking... What is it that you are populating in Word? Sounds like using a template .dot file and bookmarks may be better and easier. No need to move the cursor around.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|