.NET Forum / Visual Studio.NET / VS Tools for Office / March 2005
Change CmmandBars in a Single Instance Only?
|
|
Thread rating:  |
Bruce Hutfless - 21 Aug 2004 02:01 GMT Help!
Assumming, vb.Net, VSTO, and Office Pro 2004 ---
How do I modify which CommandBars are visible in only my instance instead of all instances.
Now, Let my explain, assumming a vb.Net Windows Forms application which creates and instance if the Word.Application object and then a instance of Word.Document object from a template, how do effect changes to the Commandbar for this instance only.
For example, if I create an instance of Word.Application, and I make a change to any of the CommandBars, (e.g., "Standard"), and I as a user lauch another instance of Word (Start, Programs,Microsoft Office, Word 2003) it too will have it's toolbar modified. This is not the behavior I want to occur. I want only my instance of Word to display different CommandBars.
Any ideas of help would be greatly appreciated.
I have code samples if that becomes necessary.
I'm trying to migrate and Vb 6 Office Add-in to VST0, in the past I wrote C DLL's that hooked specific Word messages to modify the behavior of word. I believe that other corporate / enterprise users are going to what the same kind of thing.
Regards,
Bruce Hutfless SchoolKiT Internationa
"Paul Cornell [MS]" - 24 Aug 2004 00:33 GMT It sounds like you are trying to automate Word from a Windows Forms application. If you use a VSTO Word application, you can modify toolbars on that document instance only. You can also interact with a Windows from from a VSTO application.
For examples (they're Excel, but you'll get the idea), see "Walkthrough: Creating Custom Menu Items in Excel" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto200 3_ta/html/odc_VSTCommBar.asp?frame=true and "Walkthrough: Collecting Data Using a Windows Form" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/h tml/wrwlkUsingWinFormToObtainUserInput.asp?frame=true.
Regards, Paul Cornell Documentation Manager Microsoft Developer Division User Education ------------------------------------ This posting is provided "AS IS" with no warranties, and confers no rights.
Bruce Hutfless - 24 Aug 2004 17:29 GMT Paul,
Thanks for responding, I will investigate the links you provide and see if that anwers my question.
You are correct in the I am trying to automate Word froma Windows Forms application. (Office 2003 Pro).
My understanding is that a VSTO application is either a document or a template, rather than a Windows Forms.
Since, the previous "add-in dll' (Office 8 & 9 (Word)) which had to be built for each version of Office, is the basis of a content publishing tools.
I would love to see the Word Document Window exposed as a control much like Internet Explorer's shdocvw.dll with all methods and events exposed. Maybe some day!
I'll let you know how it goes.
Regards,
Bruce Hutfless Chief Engineer SchoolKiT International http://www.schoolkit.com
> It sounds like you are trying to automate Word from a Windows Forms > application. If you use a VSTO Word application, you can modify toolbars [quoted text clipped - 18 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. Bruce Hutfless - 31 Aug 2004 00:28 GMT Paul,
After, almost a week nothing works correctly, there is no document context available in VSTO.
For, example, build VSTO Word Document project in the Document_Open and Document_Close add commandBar.
Launch project Debug Run (F5).
Now from Windows XP GUI choose Start->All Programs->Microsoft Office->Microsoft Office Wored 2003
and commandbar "Standard" is missing.
Dosn't matter whether I use Document or template I get the same result. For that matter I get the same thing in Excel.
Do you or any body at Microsoft have working code?
Here the Document_Open() function
' Called when the document is opened.
Private Sub ThisDocument_Open() Handles ThisDocument.Open
ThisApplication.Visible = False
For Each oCommandBar As Office.CommandBar In ThisDocument.CommandBars
If oCommandBar.Name = "Standard" Then
oCommandBar.Enabled = False
End If
Next
ThisApplication.Visible = True
End Sub
And the Document_Close() Function
' Called when the document is opened.
Private Sub ThisDocument_Open() Handles ThisDocument.Open
ThisApplication.Visible = False
For Each oCommandBar As Office.CommandBar In ThisDocument.CommandBars
If oCommandBar.Name = "Standard" Then
oCommandBar.Enabled = True
End If
Next
ThisApplication.Visible = True
End Sub
Regards,
Bruce Hutfless
> It sounds like you are trying to automate Word from a Windows Forms > application. If you use a VSTO Word application, you can modify toolbars [quoted text clipped - 18 lines] > This posting is provided "AS IS" with no warranties, and confers no > rights. Michael Whalen - 31 Aug 2004 00:57 GMT In your original message, you were trying to set the properties of the command bars for a single instance of a Word document. Have you tried setting the context of the application to the current document? The default is normal.dot, so any changes will get stored there and reappear the next time you launch Word. Try adding:
ThisDocument.Application.CustomizationContext = ThisDocument.Application.ActiveDocument
before making any changes to the command bars and see if that helps your case.
Michael Whalen Software Developer, Customer Solutions Team, VSTO ---------- This posting is provided "AS IS" with no warranties, and confers no rights.
> Paul, > [quoted text clipped - 73 lines] > > For examples (they're Excel, but you'll get the idea), see "Walkthrough: > > Creating Custom Menu Items in Excel" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto200
> > 3_ta/html/odc_VSTCommBar.asp?frame=true and "Walkthrough: Collecting Data > > Using a Windows Form" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/h
> > tml/wrwlkUsingWinFormToObtainUserInput.asp?frame=true. > > [quoted text clipped - 5 lines] > > This posting is provided "AS IS" with no warranties, and confers no > > rights. Bruce Hutfless - 03 Sep 2004 01:52 GMT Michael,
I've worked the CommandBar issues and that is working correctly, however I still have a nagging problem.
Question: How do I delete the "Normal.dot" template?
Assume the following code:
' Start Word.
ThisApplication = New MSWord.Application
ThisDocument = ThisApplication.Documents.Add(Template:="C:\Source Code\Dev\WFBruce\MyNormal.dot")
For Each oTmpl As MSWord.Template In ThisApplication.Templates
If oTmpl.Name = "Normal.dot" Then
'======> what goes here to delete Normal.dot from templates collection? <===============
End If
Next
ThisDocument.SaveAs("C:\Source Code\Dev\WFBruce\MyDocument.doc")
ThisDocument = ThisApplication.Documents.Open("C:\Source Code\Dev\WFBruce\MyDocument.doc")
ThisDocument.Application.CustomizationContext = ThisDocument.Application.ActiveDocument()
For Each oCommandBar As Office.CommandBar In ThisApplication.CommandBars
If oCommandBar.Name = "Standard" Then
oCommandBar.Enabled = False
End If
Next
It has take me awhile, but this the last major hurdle.
I've got all of the events wired, and I can launch and close Word from my Windows.Forms based vb.Net Visual Studio .Net 2003 project correctly.
I just need to remove all reference to Normal.dot and then I'm on my way.
Any help woould be greatly appreciated.
Regards,
Bruce Hutfless Chief Engineer SchoolKiT International web: http://www.schoolkit.com email: bhutfless@schoolkit.com
> In your original message, you were trying to set the properties of the > command bars for a single instance of a Word document. Have you tried [quoted text clipped - 112 lines] >> > This posting is provided "AS IS" with no warranties, and confers no >> > rights. Michael Whalen (MS) - 07 Sep 2004 19:31 GMT I'm not sure how to do that - I'll see what I can find out. I'm curious as to why you'd want to get rid of the normal.dot template. Are you basing your document on another template? If you don't want to use normal.dot, then why don't you create the document based on the template you want to use?
Your questions seem to be more about the Word Object Model and not about VSTO - the problems you're having would be the same whether you're using VSTO or VBA to customize your document. Have you considered asking these questons in a more appropriate newsgroup? Perhaps someone at microsoft.public.officedev will have better information about the specifics of the Word OM.
Michael Whalen Software Developer, Customer Solutions Team, VSTO ---------- This posting is provided "AS IS" with no warranties, and confers no rights.
> Michael, > [quoted text clipped - 158 lines] > >> > "Walkthrough: > >> > Creating Custom Menu Items in Excel" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto200
> >> > 3_ta/html/odc_VSTCommBar.asp?frame=true and "Walkthrough: Collecting > > Data > >> > Using a Windows Form" at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/h
> >> > tml/wrwlkUsingWinFormToObtainUserInput.asp?frame=true. > >> > [quoted text clipped - 5 lines] > >> > This posting is provided "AS IS" with no warranties, and confers no > >> > rights. Bruce Hutfless - 07 Sep 2004 23:19 GMT Michael,
I you see my code below; I'm trying to create a document with my own template!
How, Word is attaching the Normal.dot and storing changes in Normal.dot rather than my template.
Therefore, I need to remove Normal.dot from my document before I say it.
If there is a better way to create a dcoument based solely on "MyTemplate.dot", I'm all ears.
Regards,
Bruce Hutfless Chief Engineer SchoolKiT International web: http://www.schoolkit.com email: bhutfless@schoolkit.com
> I'm not sure how to do that - I'll see what I can find out. I'm curious as > to why you'd want to get rid of the normal.dot template. Are you basing [quoted text clipped - 201 lines] >> >> > This posting is provided "AS IS" with no warranties, and confers no >> >> > rights. Cindy M -WordMVP- - 29 Mar 2005 21:50 GMT Hi Bruce,
> How, Word is attaching the Normal.dot and storing changes in Normal.dot > rather than my template. > > Therefore, I need to remove Normal.dot from my document before I say it. If you use the Documents.Add method and specify a template name, your document will be based on and attached to that template.
However, Word also has the concept of GLOBAL templates, that act as native Addins. The Normal.dot template is ALWAYS available in Word, there's no way to change that; you can't delete it; you can't unload it. Other templates might also be loaded as Addins, in the UI you can see and manage this list in Tools/Templates and Addins.
WHY is the normal.dot bothering you?
-- Cindy
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|