Results 1 to 2 of 2

Thread: VBA Menus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2004
    Posts
    144

    VBA Menus

    Hey all is it possible in VBA to create menus such as File, Edit to be placed at the top of a program i'm creating if so could anyone help?

    thanks

    James Bowtell

  2. #2
    Addicted Member
    Join Date
    Jan 2002
    Location
    Glasgow, Scotland
    Posts
    202

    Re: VBA Menus

    James,

    here is an example of custom menu which i have in a module, and which run at start up.

    VB Code:
    1. Sub db_Open(Cancel As Integer)
    2. Dim mymenubar As CommandBar
    3. Dim newmenu As CommandBarControl
    4. Dim ctrl1 As CommandBarButton
    5. Dim ctrl2 As CommandBarButton
    6. Dim ctrl3 As CommandBarButton
    7.  
    8. 'set up custom menu bar to allow office links and print.
    9. 'standard ones are disabled in start up options for security
    10. 'the menu bar is reset on close of the db
    11.  
    12. Set mymenubar = CommandBars.ActiveMenuBar
    13.  
    14. Set newmenu = mymenubar.Controls.Add(Type:=msoControlPopup, Temporary:=True)
    15.     newmenu.Caption = "Publish"
    16.    
    17. Set ctrl1 = newmenu.Controls.Add(Type:=msoControlButton, Id:=1)
    18.     With ctrl1
    19.         .Caption = "Publish - Word"
    20.         .TooltipText = "Publish in Microsoft Word"
    21.         .Style = msoButtonCaption
    22.         .OnAction = "Publish_Word"
    23.     End With
    24.    
    25. Set ctrl2 = newmenu.Controls.Add(Type:=msoControlButton, Id:=2)
    26.     With ctrl2
    27.         .Caption = "Publish - Excel"
    28.         .TooltipText = "Publish in Microsoft Excel"
    29.         .Style = msoButtonCaption
    30.         .Enabled = True
    31.         .OnAction = "Publish_Excel"
    32.     End With
    33.    
    34. Set ctrl3 = newmenu.Controls.Add(Type:=msoControlButton, Id:=3)
    35.     With ctrl3
    36.         .Caption = "Print"
    37.         .TooltipText = "Print Report"
    38.         .Style = msoButtonCaption
    39.         .Enabled = True
    40.         .OnAction = "Print_Report"
    41.     End With
    42.  
    43. End Sub
    44.  
    45. Private Sub db_Close()
    46. Dim mymenubar As CommandBar
    47.  
    48. Set mymenubar = CommandBars.ActiveMenuBar
    49.  
    50. mymenubar.Reset
    51.  
    52. End Sub

    I have macros for each of the menu options. i couldnt get it to work with code (was a while ago i wrote this).

    the macros, are basic 'output to', or print out

    HTH
    if you fail to plan, you plan to fail

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