Alex Haan
2007-03-07 09:36:00 UTC
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.
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.