|
-
Sep 9th, 2005, 10:48 AM
#1
[RESOLVED] Avoid Mutexing with my Instance of Word
How can I avoid mutexing of word with my instance. It should not open the documents opened by user (by dbl-clicking on icon) in my instance of Word.
This is because I open documents in my instance, do some manupulation and finally close it without saving any files. So chances of user losing his file is high.
Pradeep
Last edited by Pradeep1210; Sep 9th, 2005 at 10:53 AM.
-
Sep 9th, 2005, 11:07 AM
#2
Re: Avoid Mutexing with my Instance of Word
keep your instance hidden.
the user won't see it and can't manipulate it.
 why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
for every question you ask provide an answer on another thread.
-
Sep 9th, 2005, 11:38 AM
#3
Re: Avoid Mutexing with my Instance of Word
That will not work since when you create your word object and set it to false for visibility and either shell a doc file or doubleclick a doc file it will open and show the app object. Then if you click on the Windows menu it will show both documents. The use can still switch to your programmed one and manipulate it etc.
VB Code:
Option Explicit
Private moApp As Word.Application
Private Sub Command1_Click()
Set moApp = New Word.Application
moApp.Visible = False
moApp.Documents.Add
moApp.Documents(1).Select
moApp.Selection.TypeText "Test"
End Sub
Private Sub Command2_Click()
'Or dont shell and just doubleclick on a doc file
Shell "D:\Program Files\Microsoft Office\OFFICE11\Winword.exe D:\Test.doc", vbMaximizedFocus
End Sub
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 
-
Sep 10th, 2005, 01:30 PM
#4
Re: Avoid Mutexing with my Instance of Word
How do we avoid this?
Pradeep
-
Sep 10th, 2005, 01:41 PM
#5
Re: Avoid Mutexing with my Instance of Word
You can use the "/w" commandline switch to create a new separate instance of Word. If the user double clicks a desktop shortcut to Word or clicks a menu item for Word, it will still do the same. 
VB Code:
Option Explicit
Private moApp As Word.Application
Private Sub Command1_Click()
Set moApp = New Word.Application
moApp.Visible = False
moApp.Documents.Add
moApp.Documents(1).Select
moApp.Selection.TypeText "Test"
End Sub
Private Sub Command2_Click()
'shell and create a new separate instance of Word.
'The Windows menu will not contain any other documents, etc.
Shell "D:\Program Files\Microsoft Office\OFFICE11\Winword.exe [b]/w[/b] D:\Test.doc", vbMaximizedFocus
End Sub
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 
-
Sep 10th, 2005, 03:14 PM
#6
Re: Avoid Mutexing with my Instance of Word
But then it will not be a Word.Application object. So how will I reference this instance for the documents I want to open and manupulate from my code?
Pradeep
-
Sep 10th, 2005, 03:35 PM
#7
Re: Avoid Mutexing with my Instance of Word
You can create a separate app object variable/
VB Code:
Option Explicit
Private moApp1 As Word.Application
Private moApp2 As Word.Application
Private Sub Command1_Click()
Set moApp1 = New Word.Application
moApp1.Visible = True
moApp1.Documents.Add
moApp1.Documents(1).Select
moApp1.Selection.TypeText "Command1"
End Sub
Private Sub Command2_Click()
'shell and create a new separate instance of Word.
'The Windows menu will not contain any other documents, etc.
Shell "D:\Program Files\Microsoft Office\OFFICE11\Winword.exe /w D:\Test.doc", vbMaximizedFocus
End Sub
Private Sub Command3_Click()
Set moApp2 = New Word.Application
moApp2.Visible = True
moApp2.Documents.Add
moApp2.Documents(1).Select
moApp2.Selection.TypeText "Command3"
End Sub
This will create 3 separate Wod instances and all three will not have "Window" menu access to each other.
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 
-
Sep 10th, 2005, 04:46 PM
#8
Re: Avoid Mutexing with my Instance of Word
So when the user double clicks on any .doc file to open it, will it will open in a fourth instance and When I close these 3 instances, that document won't be closed?
Pradeep
-
Sep 10th, 2005, 05:00 PM
#9
Re: Avoid Mutexing with my Instance of Word
If a user doubleclicks a doc file or opens a new instance of Word from the start menu it will open in the first instance of Word, thus sharing the Window menu with the programmitacally opened docs. 
You would have to add the "/w" switch to the standard Word menu item to prevent it.
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 
-
Sep 10th, 2005, 05:59 PM
#10
Re: Avoid Mutexing with my Instance of Word
I got the point of starting it with /w switch. But the problem is how to get a reference to the Word instance I started with /w switch to set to my object variable so that I can use it in my program?
Some kind of:
VB Code:
Set moApp2 = Shell ("D:\Program Files\Microsoft Office\OFFICE11\Winword.exe /w D:\Test.doc", vbMaximizedFocus)
End Sub
Pradeep
-
Sep 10th, 2005, 06:23 PM
#11
Re: Avoid Mutexing with my Instance of Word
The programmed instance is fine as well as the swith but it only depends on if the user manually opens another instance of Word after that. If they do, it will attach to what ever instance is open already.
VB Code:
Option Explicit
Private moApp3 As Word.Application
Private Sub Command4_Click()
Shell "D:\Program Files\Microsoft Office\OFFICE11\Winword.exe /w D:\Test.doc", vbMaximizedFocus
Dim i As Integer
Dim bFound As Boolean
i = 1
Do
Set moApp3 = GetObject(, "Word.Application")
If moApp3.Documents(i).Name = "Test.doc" Then
bFound = True
Exit Do
End If
i = i + 1
Loop
If bFound = True Then
moApp3.Documents(i).Select
Else
Set moApp3 = Nothing
MsgBox "Word Doc not found!"
End If
End Sub
This will get the shelled instance but again, if the user opens another instance of Word, it will share the app object.
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 
-
Sep 10th, 2005, 07:13 PM
#12
Re: Avoid Mutexing with my Instance of Word
Is there no method to disable mutexing altogether (even if the changes are systemwide)?
Pradeep
-
Sep 10th, 2005, 07:49 PM
#13
Re: Avoid Mutexing with my Instance of Word
Not from within Word. I just searched. You will have to go to File Types, and modify the DOC filetype. Just add the "/w" switch to the OPEN property.
-
Sep 10th, 2005, 08:03 PM
#14
Re: Avoid Mutexing with my Instance of Word
That is what I have pointed out earlier.
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 
-
Sep 10th, 2005, 08:20 PM
#15
Re: Avoid Mutexing with my Instance of Word
 Originally Posted by robdog888
You would have to add the "/w" switch to the standard Word menu item to prevent it.
That one? I didn't even understand it. I went looking in Word for an option to open in the same window, but didn't find one, so I posted.
-
Sep 10th, 2005, 09:17 PM
#16
Re: Avoid Mutexing with my Instance of Word
Right, it doesnt have one. It would require you to add the switch to the start menu, quick launch (if added), and desktop shortcut.
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 
-
Sep 10th, 2005, 09:19 PM
#17
Re: Avoid Mutexing with my Instance of Word
Still wouldn't work to double-click on a .DOC file, without changing the filetype
-
Sep 10th, 2005, 09:20 PM
#18
Re: Avoid Mutexing with my Instance of Word
Yes, there too. Anyplace the user can start a Word instance you would have to add it.
Edit: Moved to Office Development
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 
-
Sep 11th, 2005, 02:40 AM
#19
Re: Avoid Mutexing with my Instance of Word
Thanks a lot both of you. I got the point - just conquer all ways the user can open a document and use the /w switch there.
In file association with .DOC files, it is :
"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /n /dde
Should I change it to:
"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /w
Pradeep
-
Sep 11th, 2005, 03:13 AM
#20
Re: Avoid Mutexing with my Instance of Word
No, read this:
http://support.microsoft.com/default...b;en-us;210565
Here are the command switches, but may be for Word 2003:
/safe
Start Word in Office Safe Mode.
/ttemplatename
Start Word with a new document based on a template other than the Normal template (Normal template: A global template that you can use for any type of document. You can modify this template to change the default document formatting or content.). Example: /tMyfax.dot
Note If the file name has spaces in it, enclose the complete name in quotation marks — for example, /t"Elegant Report.dot"
Security Because templates can store macro viruses, be careful about opening them or creating files based on new templates. Take the following precautions: run up-to-date antivirus software on your computer, set your macro security level to high, clear the Trust all installed add-ins and templates check box, use digital signatures, and maintain a list of trusted sources.
/pxslt
Start Word with a new XML document based on the specified Extensible Stylesheet Language Transformation (XSLT) (XSL Transformation (XSLT): A file that is used to transform XML documents into other types of documents, such as HTML or XML. It is designed for use as part of XSL.). Example: /p:c:\MyTransform.xsl
/a
Start Word and prevent add-ins (add-in: A supplemental program that adds custom commands or custom features to Microsoft Office.) and global templates (including the Normal template) from being loaded automatically. The /a switch also locks the setting files.
/laddinpath
Start Word and then load a specific Word add-in. Example: /lSales.dll
Security Use caution when running executable files or code in macros or applications. Executable files or code can be used to carry out actions that might compromise the security of your computer and data.
/m
Start Word without running any AutoExec macros (macro: An action or a set of actions you can use to automate tasks. Macros are recorded in the Visual Basic for Applications programming language.).
/mmacroname
Start Word and then run a specific macro. The /m switch also prevents Word from running any AutoExec macros. Example: /mSalelead
Security Because macros can contain viruses, be careful about running them. Take the following precautions: run up-to-date antivirus software on your computer; set your macro security level to high; clear the Trust all installed add-ins and templates check box; use digital signatures; maintain a list of trusted publishers.
/n
Start a new instance of Word with no document open. Documents opened in each instance of Word will not appear as choices in the Window menu of other instances.
/w
Start a new instance of Word with a blank document. Documents opened in each instance of Word will not appear as choices in the Window menu of the other instances.
Last edited by dglienna; Sep 11th, 2005 at 03:29 AM.
-
Sep 11th, 2005, 08:04 AM
#21
Re: Avoid Mutexing with my Instance of Word
From command line or shortcut it's OK. But to disable mutexing alltogether on my system
should I edit my file associations to:
"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /w
Usually users just double-click the DOC file to open it.
Pradeep
-
Sep 11th, 2005, 11:58 AM
#22
Re: Avoid Mutexing with my Instance of Word
Yes, thats the link I got the /w from. As long as your not needing to distribute your app then it doesnt matter if you place it all over. It would be a different story if you were though.
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 
-
Sep 11th, 2005, 02:17 PM
#23
Re: Avoid Mutexing with my Instance of Word
Thanks a lot. It's resolved for now.
One last question before finally closing this thread :
How much do I pay in terms of memory and CPU to avoid mutexing? Does mutexing reduce CPU and memory load to a great extent?
Pradeep
-
Sep 11th, 2005, 02:24 PM
#24
Re: Avoid Mutexing with my Instance of Word
It could depending on th number of instances of Word you create. When you dont mutate, ut costs you about 300~500 Kb for each additional instance, but when you create separate instances it wil cost a whole lot more like 15 Mb each.
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 
-
Sep 11th, 2005, 02:57 PM
#25
Re: Avoid Mutexing with my Instance of Word
Got it 
Mutexing : First Instance 15MB, successive instances - 500KB
Individual : 15MB per instance !!
So I'll just have to keep in mind to keep the number of open documents as low as possible. right?
Pradeep
-
Sep 11th, 2005, 03:08 PM
#26
Re: Avoid Mutexing with my Instance of Word
Problem resolved 
Thanks a lot RobDog and David
I wish I could rate the threads here, but the system just prevents it. But please accept my sincere thanks anyway.
Pradeep
-
Sep 11th, 2005, 03:16 PM
#27
Re: [RESOLVED] Avoid Mutexing with my Instance of Word
Thanks for the Thanks 
The "system" is just probably the spread. You need to give out a few more Reps before you can Rep again.
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
|