Results 1 to 6 of 6

Thread: word vba popup menu

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2005
    Posts
    83

    word vba popup menu

    i have a popup menu and i want there to be no more than two controls on it as some of the controls i add are duplicating

    is there anyway of saying only add control if there are less than two controls already.

    or else saying if controls.count > 2 then delete the last one in?

    here's my code for adding a control

    With clarpop.Controls.Add(Type:=msoControlButton, Temporary:=True)
    .Caption = Trim(mi)
    .Visible = True
    .BeginGroup = True
    .FaceId = 163
    End With

    thanks

  2. #2
    Junior Member
    Join Date
    Mar 2005
    Location
    Kaiserslautern, Germany
    Posts
    25

    Re: word vba popup menu

    hi
    assuming that clarpop is a CommandBarPopup...

    VB Code:
    1. If (clarpop.Count < 2) Then
    2.   With clarpop.Controls.Add(Type:=msoControlButton, Temporary:=True)
    3.     .Caption = Trim(mi)
    4.     .Visible = True
    5.     .BeginGroup = True
    6.     .FaceId = 163
    7.   End With
    8. End If

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

    Re: word vba popup menu

    You need to use the Control collection of the popup.
    VB Code:
    1. If (clarpop.Controls.Count < 2) Then
    2.   With clarpop.Controls.Add(Type:=msoControlButton, Temporary:=True)
    3.     .Caption = Trim(mi)
    4.     .Visible = True
    5.     .BeginGroup = True
    6.     .FaceId = 163
    7.   End With
    8. End If
    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

  4. #4
    Junior Member
    Join Date
    Mar 2005
    Location
    Kaiserslautern, Germany
    Posts
    25

    Re: word vba popup menu

    RobDog please implement some kind of Code-Completion into the message editor

  5. #5
    New Member
    Join Date
    Mar 2005
    Location
    Essex
    Posts
    14

    Re: word vba popup menu

    im not sure
    Steve

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

    Re: word vba popup menu

    Something like this. It will search for the menuitem and if it doesnt already exist then it will add it.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim oApp As Word.Application
    5.     Dim oMenu As Office.CommandBar
    6.     Dim clarpop As Office.CommandBarPopup
    7.     Dim oTemp As Office.CommandBarButton
    8.    
    9.     Set oApp = New Word.Application
    10.     Set oMenu = oApp.CommandBars("Menu Bar")
    11.     Set clarpop = oMenu.Controls("YourPopup")
    12.     Set oTemp = oMenu.FindControl(msoControlButton, "ItsID", "AnyTagValue", False, True)
    13.     If TypeName(oTemp) <> "Nothing" Then
    14.         'Already exists
    15.     Else
    16.         With clarpop.Controls.Add(msoControlButton, True)
    17.             .Caption = Trim(mi)
    18.             .Visible = True
    19.             .BeginGroup = True
    20.             .FaceId = 163
    21.         End With
    22.     End If
    23. End Sub
    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