Results 1 to 2 of 2

Thread: Building a menu bar for Excel using a VB6 DLL

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    1

    Building a menu bar for Excel using a VB6 DLL

    I have built a DLL using VB 6.0. One of the functions of the DLL is to build a custom menu bar in Excel. I have setup a class with the necessary code to create the menu and it appears to work properly. However, the menu options are not built in the currect version of Excel. Rather, they only appear when I open up Excel from scratch.

    My logic in Excel to call my DLL is as follows:
    VB Code:
    1. Private Sub Workbook_Open()
    2.    
    3.   Dim objMenu         As Object
    4.    
    5.   Set objMenu = CreateObject("adcxxx.clsMyClass")
    6.  
    7.   objMenu.Add_Menu_Options  
    8.  
    9. End Sub--------------------------------------------------------------------------------My DLL contains the following logic:
    10. visual basic code:--------------------------------------------------------------------------------Sub Add_Menu_Options()
    11.  
    12.     Dim intHelpMenu             As Integer
    13.     Dim cbrMainMenuBar          As CommandBar
    14.     Dim cstmMyMenu                As CommandBarControl
    15.     Dim menu                    As CommandBarControl
    16.    
    17.     ' Remove the Ellipse menu option if it already exists
    18.     On Error Resume Next
    19.     Application.CommandBars("Worksheet Menu Bar").Controls("E&llipse").Delete
    20.     On Error GoTo 0
    21.  
    22.     ' Set a CommandBar variable to Worksheet menu bar
    23.     Set cbrMainMenuBar = Application.CommandBars("Worksheet Menu Bar")
    24.  
    25.     ' Return the Index number of the Help menu. We can then use this to place a custom menu before.
    26.     intHelpMenu = cbrMainMenuBar.Controls("Help").Index
    27.      
    28.     Set cstmMIMS = cbrMainMenuBar.Controls.Add(Type:=msoControlPopup, Before:=intHelpMenu)
    29.     cstmMIMS.Caption = "My Menu"
    30.      
    31.     With cstmMyMenu.Controls.Add(Type:=msoControlButton)
    32.          .Caption = "ERP Connect"
    33.          .OnAction = "ERP_Connect"
    34.     End With
    35.  
    36. End Sub
    --------------------------------------------------------------------------------Any help would be appreciated. Thanks - Joe
    Last edited by RobDog888; Jan 10th, 2006 at 10:17 AM. Reason: Added [vbcode] tags

Posting Permissions

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



Click Here to Expand Forum to Full Width