Group:  Microsoft Word ยป microsoft.public.word.vba.addins
Thread: Commandbar for Word Add-in

Commandbar for Word Add-in
Alex Haan 3/7/2007 9:36:00 AM
I am working on a Word Add-in in Visual Studio 2005 (C#, .Net2.0). I know
this is a VB newsgroup, but it is the best i could find.

For this add-in i need a toolbar, which i create using
'Microsoft.Office.Core.CommandBar'. and '.CommandBarButton'. It does show up
nice and events are hooked up without a problem.

But I run into problems when I want to change the button state or when
en/disabling it. In specific conditions trying to do that will result in a
COMException. I can't remember the exact exception code, but searching around
returned an 'object missing' description.

My current theory is, that my references to these buttons become invalid
after a document change/close/etc. The events are still working though, for
which i can think of some reasons.
Currently I lookup the buttons on a document change
('Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentChangeEventHandler') using:
'Microsoft.Office.Interop.Application .. CommandBars.FindControl()'. Which
is not ideal, since it requires that the captions of the buttons are unique.
And besides that, it is far from ideal anyway that this seems necessary.

Just like Jens Sauer in 'An AfterCloseEvent' I could use such an event too.
For now I'm just using the BeforeClose event, and mimic the 'do you want to
safe' dialog, so I can determine whether a document has really closed or not.
But this brings in localization issues. Ideally I'd like a 'DocumentClosing'
and 'DocumentSave' event.
Re: Commandbar for Word Add-in
"Perry" <drumper[ at ]gmail.com> 4/9/2007 9:29:57 PM
[Quoted Text]
> But this brings in localization issues. Ideally I'd like a
> 'DocumentClosing'
> and 'DocumentSave' event.

Can't do.

Alex, Word application events don't have a DocumentAfterClose()
or -AfterSave() event.
Nor is there a DocumentClosing() or a DocumentSave() event.

You'll have to work around, using the parameters and callbacks available in
the
DocumentBeforeClose() or DocumentBeforeSave() event ...

Automation clients have to deal with object- and event modell as present in
the automation server (MS Word in your case).
So you can't hookup your .NET application to these events.

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE



"Alex Haan" <Alex Haan[ at ]discussions.microsoft.com> schreef in bericht
news:D178FBD7-BC14-454D-A246-1B1DBD240E8F[ at ]microsoft.com...
>I am working on a Word Add-in in Visual Studio 2005 (C#, .Net2.0). I know
> this is a VB newsgroup, but it is the best i could find.
>
> For this add-in i need a toolbar, which i create using
> 'Microsoft.Office.Core.CommandBar'. and '.CommandBarButton'. It does show
> up
> nice and events are hooked up without a problem.
>
> But I run into problems when I want to change the button state or when
> en/disabling it. In specific conditions trying to do that will result in
> a
> COMException. I can't remember the exact exception code, but searching
> around
> returned an 'object missing' description.
>
> My current theory is, that my references to these buttons become invalid
> after a document change/close/etc. The events are still working though,
> for
> which i can think of some reasons.
> Currently I lookup the buttons on a document change
> ('Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentChangeEventHandler')
> using:
> 'Microsoft.Office.Interop.Application .. CommandBars.FindControl()'. Which
> is not ideal, since it requires that the captions of the buttons are
> unique.
> And besides that, it is far from ideal anyway that this seems necessary.
>
> Just like Jens Sauer in 'An AfterCloseEvent' I could use such an event
> too.
> For now I'm just using the BeforeClose event, and mimic the 'do you want
> to
> safe' dialog, so I can determine whether a document has really closed or
> not.
> But this brings in localization issues. Ideally I'd like a
> 'DocumentClosing'
> and 'DocumentSave' event.

Re: Commandbar for Word Add-in
"Andrei Smolin" <andrei dot smolin [ at ] add-in-express dotcom> 5/10/2007 2:30:01 PM
Hi Alex,

[Quoted Text]
> In specific conditions trying to do that will result in a COMException.

This is a usual problem with every Office app. You should re-connect your
controls when you get this exception. However, I'm afraid this is not the
only problem with those command bars and controls. You may want to check the
web-page mentioned below to find components that allow creating user
interface of your add-in in design-time (this particular problem is solved,
of course). As you may imagine, they are used on all combinations of Office
and Windows versions.

> is not ideal, since it requires that the captions of the buttons are
> unique.

Use the Tag property to identify your controls.

Regards from Belarus,
Andrei Smolin
http://www.add-in-express.com/add-in-net/

"Alex Haan" <Alex Haan[ at ]discussions.microsoft.com> wrote in message
news:D178FBD7-BC14-454D-A246-1B1DBD240E8F[ at ]microsoft.com...
>I am working on a Word Add-in in Visual Studio 2005 (C#, .Net2.0). I know
> this is a VB newsgroup, but it is the best i could find.
>
> For this add-in i need a toolbar, which i create using
> 'Microsoft.Office.Core.CommandBar'. and '.CommandBarButton'. It does show
> up
> nice and events are hooked up without a problem.
>
> But I run into problems when I want to change the button state or when
> en/disabling it. In specific conditions trying to do that will result in
> a
> COMException. I can't remember the exact exception code, but searching
> around
> returned an 'object missing' description.
>
> My current theory is, that my references to these buttons become invalid
> after a document change/close/etc. The events are still working though,
> for
> which i can think of some reasons.
> Currently I lookup the buttons on a document change
> ('Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentChangeEventHandler')
> using:
> 'Microsoft.Office.Interop.Application .. CommandBars.FindControl()'. Which
> is not ideal, since it requires that the captions of the buttons are
> unique.
> And besides that, it is far from ideal anyway that this seems necessary.
>
> Just like Jens Sauer in 'An AfterCloseEvent' I could use such an event
> too.
> For now I'm just using the BeforeClose event, and mimic the 'do you want
> to
> safe' dialog, so I can determine whether a document has really closed or
> not.
> But this brings in localization issues. Ideally I'd like a
> 'DocumentClosing'
> and 'DocumentSave' event.


Home | Search | Terms | Imprint
Newsgroups Reader