Dead menu prior to addin load?

S

srplatt

While running my (Excel) addin, I install a custom menu item (in
OnStartupComplete()). I add a menu to CommandBars along with a number
of buttons).

If I exit Excel, then re-enter without opening a specific document
(Excel opens with a blank document), the custom menu still appears but
remains inactive until some event occurs to load my addin (e.g.,
opening a previous document that uses the addin).

Is there anyway to make the custom menu active from a blank document?
(IOW, maybe a menu event/button click loads the addin?)

Thanks,
Steve
 
M

Mark Durrenberger

I'm assuming that in your addin you have an on-connection event? If so,
create your button there instead of the startup complete event.

HTH,
Mark


--
_________________________________________________________
Mark Durrenberger, PMP
Principal, Oak Associates, Inc, www.oakinc.com
"Advancing the Theory and Practice of Project Management"
________________________________________________________

The nicest thing about NOT planning is that failure
comes as a complete surprise and is not preceded by
a period of worry and depression.

- Sir John Harvey-Jones
 
S

Stephen Bullen

Hi Steve
Is there anyway to make the custom menu active from a blank document?
(IOW, maybe a menu event/button click loads the addin?)

Did you set the button's OnAction property to reference your COM Addin?
In a permanent-menu architecture (like you seem to be using), the COM
Addin is demand-loaded, by someone clicking the button. If the OnAction
property is set to something like "!<MyAddin.Connect>", Excel will load
your COM Addin when it's clicked, allowing you to set up your menu's
event hooks, before firing the _Click event.

The following code shows how to set up a permanent-menu architecture,
and is taken from "Chapter 21 - Writing Addins with Visual Basic 6" of
our new book, "Professional Excel Development":

'Run when the addin is loaded
Private Sub AddinInstance_OnConnection( _
ByVal Application As Object, _
ByVal ConnectMode As _
AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object, _
custom() As Variant)

Dim sOnAction As String

'Store a reference to the application object
Set gxlApp = Application

'If we're starting up, it must be the first time,
'so create our menu items permanently
If ConnectMode = ext_cm_Startup Then

'Get the ProgID from the AddInInst object
sOnAction = "!<" & AddInInst.ProgId & ">"

'Create our menus, passing the OnAction string
CreateMenus sOnAction
End If

'Whether at startup or after startup,
'we have to set up our event hooks
HookMenus

End Sub

'Run when the addin is unloaded
Private Sub AddinInstance_OnDisconnection( _
ByVal RemoveMode As _
AddInDesignerObjects.ext_DisconnectMode, _
custom() As Variant)

'If the user chose to uninstall the addin,
'remove our menus
If RemoveMode = ext_dm_UserClosed Then
RemoveMenus
End If

'Tidy up our application reference
Set gxlApp = Nothing

End Sub


Regards

Stephen Bullen
Microsoft MVP - Excel
www.oaltd.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top