Consulting

Results 1 to 4 of 4

Thread: Actioncontrol for short cut menus

  1. #1

    Actioncontrol for short cut menus

    Hi everyone,

    I have started a COM Addin project for Word and Excel. I am transferring a bunch of macros from templates and my personel.xls into this addin.

    I have set up part of the custom Word toolbar and got that working using With Events. I am now working on modifying various shortcut menus to add in options like 'Insert Cross Reference', 'Insert Bookmark' and 'Paste Special'.

    The way I had it in the old template was to use the ActionControl property after setting up the commandbarbutton on the shortcut menu. I have put the buttons on the respective shortcut menus OK, but the ActionControl is not working.

    This is the OnConnection procedure:
    [VBA]
    Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
    Set HostApp = Application

    Call wdMenu.InitCmdBarCustomizations
    End Sub
    [/VBA]

    The wdMenu.InitCmdBarCustomizations procedure sets the custom toolbar and then the following procedures for the short cut menus:

    [VBA]
    Option Explicit

    Public HostApp As Object
    Dim HostCmdBars As Office.CommandBars
    Dim CBEvents As New CmdBarEvents

    Private Sub MenItemsArrangement()
    Dim cmdTextMenu As Office.CommandBarButton

    On Error GoTo exitsubnow

    Call GetCommandBars
    Call wdMenu.ResetMenus

    Set cmdTextMenu = HostCmdBars("text").Controls.Add(Type:=msoControlButton)
    With cmdTextMenu
    .Caption = "Insert Bookmark"
    .FaceId = 1678
    .Tag = "TextBookMark"
    .BeginGroup = True
    Set CBEvents.cmdTextMenu = cmdTextMenu
    End With

    exitsubnow:

    End Sub

    Sub GetCommandBars()
    If HostApp.Name = "Outlook" Then
    Set HostCmdBars = HostApp.ActiveExplorer.CommandBars
    Else
    Set HostCmdBars = HostApp.CommandBars
    End If
    End Sub

    Sub ResetMenus()
    HostCmdBars("text").Reset
    End Sub

    Sub DetermineMenu(ByRef sWhichDiag As String)
    If sWhichDiag = "TextBookMark" Or sWhichDiag = "HelloEveryone" Then HostApp.Dialogs(wdDialogInsertBookmark).Show
    End Sub
    [/VBA]

    Last but not least the class module CmdBarEvents has the following code:
    [VBA]
    Public WithEvents cmdTextMenu As Office.CommandBarButton

    Private Sub cmdTextMenu_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
    Dim cmdBCtl As CommandBarControl

    Set cmdBCtl = HostApp.CommandBars.ActionControl
    Call wdMenu.DetermineMenu(cmdBCtl.Tag)
    End Sub
    [/VBA]

    The trouble is that the code runs fine through [VBA]Set cmdBCtl = HostApp.CommandBars.ActionControl[/VBA] but doesn't set the cmdBCtl. When the next line is excuted, because there is nothing there the tag can't be read.

    I hope this makes sense and someone can help.

    Cheers,
    Andrew

  2. #2
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    My experience has been that it is easier to build an ActivX Dll that contains the macro code rather than use a COM Add-in.

  3. #3
    Hi Howard,

    Unfortunately, I need to write the addin for Office 2000. Have you done this sort of thing with ActiveX DLLs?

    Do you know if it is also possible to access a macro in a DLL from the MACROBUTTON field code?

    Cheers,
    Andrew

  4. #4
    VBAX Mentor
    Joined
    Sep 2004
    Location
    Nashua, NH, USA
    Posts
    489
    Location
    Quote Originally Posted by hairywhiterabbit
    Hi Howard,

    Unfortunately, I need to write the addin for Office 2000. Have you done this sort of thing with ActiveX DLLs?
    Yes.

    Do you know if it is also possible to access a macro in a DLL from the MACROBUTTON field code?
    A stub macro is still included in the template, but all other code is in the DLLs.

    For example, the following is the code for the Auto macros in my Normal.dot. All the real code is in a DLL.

    Option Explicit
    Public clsWordVBNormal As WordVBNormal
    
    Public Sub AutoClose()
    	SetupClass
    	clsWordVBNormal.AutoClose
    End Sub
    
    Public Sub AutoExec()
    	' Runs only when global
    	SetupClass
    	clsWordVBNormal.AutoExec
    End Sub
    
    Public Sub AutoExit()
    	SetupClass
    	clsWordVBNormal.AutoExit
    End Sub
    
    Public Sub AutoNew()
    	SetupClass
    	clsWordVBNormal.AutoNew
    End Sub
    
    Public Sub AutoOpen()
    	SetupClass
    	clsWordVBNormal.AutoOpen
    End Sub
    
    Private Sub SetupClass()
    	If clsWordVBNormal Is Nothing Then
    		Set clsWordVBNormal = New WordVBNormal
    		clsWordVBNormal.SetClass Application
    	End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •