
Button doesn't work in new document
John,
COM add-ins are different from the normal add-ins. Since I do not have
access to the complete code that you've used, let's understand how the
OnAction property functions in a COM Add-in and matters will hopefully
be clearer.
While using COM add-ins, Office 2000 hooks into the button click event
internally to parse the OnAction string before the host application(Word
in this case) receives the click event. If the syntax of the string
qualifies
the criteria set for COM add-ins, Office 2000 will handle the event.
Otherwise, the host application will deal with it.
Syntax for COM Add-ins is so:
.OnAction = !<ProgID>
If the OnAction string contains a ProgID (the programmatic identifier for
the add-in), it is converted to a CLSID (a globally unique number), and
Office enumerates through the registry to locate the associated, registered
COM add-in. The COM add-in would have an event sink set to handle the
button's click event. This is done by setting a variable with the
WithEvents keyword to receive the click event specific to the button object
created. When the button control is clicked (for the event variable), the
code in the associated event handling routine is executed.
Now consider a situation when the OnAction property in the COM add-in is set
as so:
.OnAction = "MyMacro"
In this scenario Office will be unable to locate the ProgID, so the button
click event will be passed on to the next handler, which is located in the
host application. The host app will either execute the macro
(if found) or else will announce an error if it does not match any valid
macro names.
Hope this helps. In case you have any further questions, you are most
welcome to post them.
--
Regards
Shyam Pillai
http://www.*-*-*.com/
Please reply in newsgroup - No email replies .
...
Quote:
> I've got a AddIn for Word2000 using the code below, this owkr great
initially but if I open a new document the menu is created alright but the
buttons don't appear to do anything. I suspect this is something to do with
have a different object reference between the original document & the new
one, but anybody have any idea how to fix this so the buttons will work with
every document.
Quote:
> N.B. I got it working using the "onaction" property and macros in a
template, but I'd prefer it if I had everything in a single AddIn.
Quote:
> Dim pdMenu As CommandBarPopup
> Dim WithEvents About As office.CommandBarButton
> Private Sub AddinInstance_OnConnection(ByVal Application As Object, _
> ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, _
> ByVal AddInInst As Object, custom() As Variant)
> On Error Resume Next
> Dim menubar As CommandBar
> Set menubar = Application.CommandBars("Menu Bar")
> ' Add popup menu to menu bar
> Set pdMenu = menubar.Controls.Add(msoControlPopup,
Before:=menubar.Controls.Count)
Quote:
> pdMenu.Caption = "PullDown"
> pdMenu.Visible = True
> Dim pdcontrols As CommandBarControls
> Set pdcontrols = pdMenu.Controls
> ' Add button to menu
> Set About = pdcontrols.Add(msoControlButton)
> About.Caption = "button"
> End Sub
> Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As _
> AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
> On Error Resume Next
> ' Remove menu when finished
> pdMenu.Delete
> End Sub
> Private Sub About_Click(ByVal Ctrl As office.CommandBarButton, _
> CancelDefault As Boolean)
> ' Called when button pressed
> MsgBox "button Pressed"
> End Sub
> --
> "When we{*filter*}up in testing, it isn't because we only ran 5000 tests and
should
> have run 5001. It's because we totally forgot an entire area to test."
> "Software Quality Assurance Engineer" Tel. +44 (0) 131 468 8209
> PeopleDoc Ltd, Edinburgh, Scotland Fax. +44 (0) 131 468 4689