P
ParanoidMike
I haven't had any response so far - perhaps a more attention-getting
Subject will help? If anyone has any suggestions on what I should try
to modify in my VSTO code, to get these toolbar buttons to actually
run the code I've tried to connect to them, I'd sure appreciate the
help.
e.g. even though I've declared each CommandBarButton using the
"WithEvents" keyword *and* I've included an Event Handler subroutine
for the button's Click event, is it necessary to actually Add the
button each time the Add-in runs?
I notice that I've coded this Add-in in a way that it only Adds the
button if it doesn't currently exist (marked with *** below), so that
after the first time I launch Word, it should never add the button
again. However, I had assumed that once the button (with its Event
Handler) was created the first time, the Event Handlers would fire on
their own without any additional Startup activity for the Add-in. Is
this a false assumption?
Thanks, Mike
Subject will help? If anyone has any suggestions on what I should try
to modify in my VSTO code, to get these toolbar buttons to actually
run the code I've tried to connect to them, I'd sure appreciate the
help.
e.g. even though I've declared each CommandBarButton using the
"WithEvents" keyword *and* I've included an Event Handler subroutine
for the button's Click event, is it necessary to actually Add the
button each time the Add-in runs?
I notice that I've coded this Add-in in a way that it only Adds the
button if it doesn't currently exist (marked with *** below), so that
after the first time I launch Word, it should never add the button
again. However, I had assumed that once the button (with its Event
Handler) was created the first time, the Event Handlers would fire on
their own without any additional Startup activity for the Add-in. Is
this a false assumption?
Thanks, Mike
I *cannot* figure out what I'm missing to get my Event Handlers to
fire when I click the buttons I've added to a VSTO toolbar
(application add-in) in Word. The code approach I've used is
patterned after a working CommandBar & CommandBarButtons I have in a
different project, and it mirrors the approach documented in "VSTO for
Mere Mortals".
Here's the setup:
- Word 2003 SP3
- Visual Studio 2005 with the VSTO and VSTO SE add-ons
- Office PIAs and other dependencies installed (since other VSTO
projects work correctly in this copy of Word)
- I've even double-checked that the CAS policy that Visual Studio
automatically configures is "correctly" allowing FullTrust to my
assemblies (via the default URL policy that VS generates)
Here's the relevant code snipped from the current project (note that
the Structure is used to simplify the setup for three similar
CommandBarButtons, but I've only shown one button here):
Private W2MWPPBar As Office.CommandBar
Private WithEvents uiConvert As Office.CommandBarButton
Structure CommandBarButtonSettings
Public BeginGroupProperty As Boolean
Public ButtonVariable As Office.CommandBarButton
Public CaptionProperty As String
Public DescriptionTextProperty As String
Public FaceIDProperty As Integer
Public StyleProperty As Office.MsoButtonStyle
Public Tag As String
Public TooltipTextProperty As String
End Structure
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
Dim commandBarsCollection As Office.CommandBars =
DirectCast(Application.CommandBars, Office.CommandBars)
If commandBarsCollection.FindControl(Tag:=TOOLBAR_NAME) Is
Nothing Then
W2MWPPBar = commandBarsCollection.Add(TOOLBAR_NAME, _
Office.MsoBarPosition.msoBarTop, _
False, _
True)
Else
W2MWPPBar = Application.CommandBars(TOOLBAR_NAME)
End If
Dim buttonSettings As New CommandBarButtonSettings()
Dim buttonsList As New ArrayList()
buttonSettings.ButtonVariable = uiConvert
buttonSettings.CaptionProperty = "Convert to Wiki"
buttonSettings.DescriptionTextProperty = "Converts Word
Documents to MediaWiki format."
buttonSettings.FaceIDProperty = 2144
buttonSettings.StyleProperty =
Office.MsoButtonStyle.msoButtonIconAndCaption
buttonSettings.Tag = "W2MWPP Convert"
buttonSettings.TooltipTextProperty = "Word2MediaWiki++ -
Convert to MediaWiki syntax"
buttonsList.Add(buttonSettings)
For Each _buttonSettings As CommandBarButtonSettings In
buttonsList
***
If W2MWPPBar.FindControl(Tag:=_buttonSettings.Tag) Is
Nothing Then
buttonSettings.ButtonVariable =
CType(W2MWPPBar.Controls.Add(1), _
Office.CommandBarButton) ***
Else
buttonSettings.ButtonVariable =
W2MWPPBar.FindControl(Tag:=_buttonSettings.Tag)
End If
With buttonSettings.ButtonVariable
.Caption = _buttonSettings.CaptionProperty
.DescriptionText =
_buttonSettings.DescriptionTextProperty
.FaceId = _buttonSettings.FaceIDProperty
.Style = _buttonSettings.StyleProperty
.Tag = _buttonSettings.Tag
.TooltipText = _buttonSettings.TooltipTextProperty
End With
End Sub
Private Sub uiConvert_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
Boolean) Handles uiConvert.Click
' Event Handler code goes here...
End Sub
If you're interested in reviewing the source code in its entirety,
you're welcome to take a look at it here:http://www.codeplex.com/word2mediawikipp/SourceControl/DirectoryView....
So: with all this code in place, does anyone have any idea why the
CommandBar buttons do *nothing* when I click on them? [I've set
breakpoints in the code at the beginning of the Event Handlers, and VS
never breaks, so I'm 99% sure the handlers never get called. However,
when I had .OnAction properties being set for each CommandBarButton, I
was getting the VBA macro errors that are called out in Cindy
Meister's responses here:http://groups.google.com/group/microsoft.public.office.developer.com....]
Thanks for any assistance anyone can provide,
Mike