Page 2 of 2 FirstFirst 12
Results 41 to 64 of 64

Thread: [RESOLVED] Can't Get Menu Code to Run

  1. #41

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    are you saying this should work? in workbook_open

    myThing5.Delete
    Set myThing5 = Application.CommandBars.Add("paul3", msoBarPopup, , True)
    UserForm1.Show vbModeless

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    No.

    What if its the first run of your workbook? The command bar will not exist so referencing it will generate an error.

    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

  3. #43

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    So something like

    vb Code:
    1. Set temp = CommandBars.FindControls(msoControlButton, , "paul6")
    2.     If temp.Count = 0 Then
    3.         Set myThing5 = Application.CommandBars.Add("paul6", msoBarPopup, , True)
    4.     ElseIf temp.Count > 0 Then
    5.         myThing5.Delete
    6.         Set myThing5 = Application.CommandBars.Add("paul6", msoBarPopup, , True)
    7.     End If
    8.     UserForm1.Show vbModeless

    except that findControls method isn't working. Any help on using the findControls method? tried using MSDN but didn't help out too much.

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    More like this...
    Code:
    Set temp = CommandBars.FindControls(msoControlButton, , "paul6")
    If TypeName(temp) = "Nothing" Then
        Set myThing5 = Application.CommandBars.Add("paul6", msoBarPopup, , True)
    End If
    UserForm1.Show vbModeless
    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

  5. #45

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Set temp = CommandBars.FindControls(msoControlButton, , "paul6") isn't working, and msdn is of no help.

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Why are you trying to look for a button when you are initially going to be looking for your commandbar?
    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

  7. #47

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    b/c button made the most sense out of these:

    msoControlActiveX
    msoControlAutoCompleteCombo
    msoControlButton
    msoControlButtonDropdown
    msoControlButtonPopup
    msoControlComboBox
    msoControlCustom
    msoControlDropdown
    msoControlEdit
    msoControlExpandingGrid
    msoControlGauge
    msoControlGenericDropdown
    msoControlGraphicCombo
    msoControlGraphicDropdown
    msoControlGraphicPopup
    msoControlGrid
    msoControlLabel
    msoControlLabelEx
    msoControlOCXDropDown
    msoControlPane
    msoControlPopup
    msoControlSpinner
    msoControlSplitButtonMRUPopup
    msoControlSplitButtonPopup
    msoControlSplitDropdown
    msoControlSplitExpandingGrid
    msoControlWorkPane

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Well as you can see the findcontrol function takes arguments of -
    FindControl([Type], [Id], [Tag], [Visible], [Recursive])
    You can leave the control type blank but when you added your command bar did you just give it a name and search for it by that name.
    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

  9. #49

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Well this isn't working either...

    Code:
    Public myThing5 As Office.CommandBar
    Public temp As Office.CommandBarControls
    
    Sub Workbook_BeforeClose(Cancel As Boolean)
    myThing5.Delete
    End Sub
    
    Sub Workbook_Open()
    Set temp = CommandBars.FindControls(, , "paul5512")
    If TypeName(temp) = "Nothing" Then
        Set myThing5 = Application.CommandBars.Add("paul5512", msoBarPopup, , True)
    End If
    UserForm1.Show vbModeless
    End Sub
    error "object var not set" on findcontrols line

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Not sure why this is so difficult but try this...

    Set temp = CommandBars.Item("paul5512")

    instead.

    Are you looking for a button or a command bar?
    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

  11. #51

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Yeah same error w/ that.

    I'm looking for w/e myThing5 is... a commandBar, I think. Is my declaration of temp incorrect?

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Well if its temp then thats different then what you had it as a few posts ago. Please post your current code so we can work with it.
    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

  13. #53

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    vb Code:
    1. Public myThing5 As Office.CommandBar
    2. Public temp As Office.CommandBarControls
    3.  
    4. Sub Workbook_BeforeClose(Cancel As Boolean)
    5. myThing5.Delete
    6. End Sub
    7.  
    8. Sub Workbook_Open()
    9. 'Set temp = CommandBars.FindControls(, , "paul")
    10. Set temp = CommandBars.Item("paul")
    11. If TypeName(temp) = "Nothing" Then
    12.     Set myThing5 = Application.CommandBars.Add("paul", msoBarPopup, , True)
    13. End If
    14. UserForm1.Show vbModeless
    15. End Sub

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Ok its Temp so shouldnt be looking for it upon load then. Should be able to just add each time. Are you getting any errors with this code?
    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

  15. #55

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Well I have to check if it's been created b/c of that strange thing that happens when IDE is opened.

    and the above code doesn't work, as

    Set temp = CommbandBars.Item("paul") gets error 91

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Add error handling for that part.
    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

  17. #57

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    I don't think error handling is the answer. I need to find if this commandbar exists already, and need a method that works. I have no working method, so error would always be thrown.

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    That is what error handling is for.

    If it errors then you know it exists when .Add or Set. Then you can resume next and continue on. If it doesnt exist then it will be all good.
    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

  19. #59

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Tried this out.. Works until IDE is opened.. Then when going back to open the form crashes again.


    Public myThing5 As Office.CommandBar
    'Public temp As Office.CommandBarControls

    Sub Workbook_BeforeClose(Cancel As Boolean)
    myThing5.Delete
    End Sub

    Sub Workbook_Open()
    'Set temp = CommandBars.FindControls(, , "paul")
    'On Error Resume Next
    'Set temp = CommandBars.Item("paull")
    'If TypeName(temp) = "Nothing" Then
    ' Set myThing5 = Application.CommandBars.Add("paull", msoBarPopup, , True)
    'End If
    'UserForm1.Show vbModeless
    'On Error GoTo 0

    On Error GoTo errHandler:
    Set myThing5 = Application.CommandBars.Add("23", msoBarPopup, , True)
    UserForm1.Show vbModeless
    errHandler:
    UserForm1.Show vbModeless
    Resume Next
    End Sub

  20. #60

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    vb Code:
    1. Public myThing5 As Office.CommandBar
    2. 'Public temp As Office.CommandBarControls
    3.  
    4. Sub Workbook_BeforeClose(Cancel As Boolean)
    5. myThing5.Delete
    6. End Sub
    7.  
    8. Sub Workbook_Open()
    9. 'Set temp = CommandBars.FindControls(, , "paul")
    10. 'On Error Resume Next
    11. 'Set temp = CommandBars.Item("paull")
    12. 'If TypeName(temp) = "Nothing" Then
    13. '    Set myThing5 = Application.CommandBars.Add("paull", msoBarPopup, , True)
    14. 'End If
    15. 'UserForm1.Show vbModeless
    16. 'On Error GoTo 0
    17.  
    18. On Error GoTo errHandler:
    19. Set myThing5 = Application.CommandBars.Add("23", msoBarPopup, , True)
    20. UserForm1.Show vbModeless
    21. errHandler:
    22.     UserForm1.Show vbModeless
    23. Resume Next
    24. End Sub

  21. #61

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    another unsuccessful try... this sucks

    vb Code:
    1. Public myThing5 As Office.CommandBar
    2. 'Public temp As Office.CommandBarControls
    3.  
    4. Sub Workbook_BeforeClose(Cancel As Boolean)
    5. myThing5.Delete
    6. End Sub
    7.  
    8. Sub Workbook_Open()
    9. On Error GoTo errHandler:
    10. Set myThing5 = Application.CommandBars.Add("2245", msoBarPopup, , False)
    11. UserForm1.Show vbModeless
    12. errHandler:
    13.     myThing5.Delete
    14.     Set myThing5 = Application.CommandBars.Add("2245", msoBarPopup, , False)
    15.     UserForm1.Show vbModeless
    16. End Sub

  22. #62

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    only thing that is not working, is when I try to open IDE while my workbook is open.. When that happens and I try to reopen my userForm... it crashes

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

    Re: [RESOLVED] Can't Get Menu Code to Run

    Try this code as it doesnt error at all for me either with opening the IDE or not.

    vb Code:
    1. Option Explicit
    2.  
    3. Public myThing5 As Office.CommandBar
    4.  
    5. Private Sub Workbook_BeforeClose(Cancel As Boolean)
    6.     If TypeName(myThing5) <> "Nothing" Then
    7.         myThing5.Delete
    8.     End If
    9. End Sub
    10.  
    11. Private Sub Workbook_Open()
    12.     On Error GoTo errHandler
    13.     Set myThing5 = Application.CommandBars.Add("2245", msoBarPopup, , False)
    14.     UserForm1.Show vbModeless
    15.     Exit Sub
    16. errHandler:
    17.     If TypeName(myThing5) = "Nothing" Then
    18.         Set myThing5 = Application.CommandBars.Item("2245")
    19.     Else
    20.         MsgBox "Unexpected Error"
    21.     End If
    22.     If UserForm1.Visible = False Then
    23.         UserForm1.Show vbModeless
    24.     End If
    25. 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

  24. #64

    Thread Starter
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    Re: [RESOLVED] Can't Get Menu Code to Run

    Great... Actually arrived at a similar piece of code through some error handling as well, but yours works fine too..

    thanks for all the help, I appreciate it much!

Page 2 of 2 FirstFirst 12

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