Results 1 to 2 of 2

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

  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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

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

    Did you create it from a Add-In VB6 project? If so are you using the passed in Application instance?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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