Results 1 to 6 of 6

Thread: Captionless MSO CommandBar !!

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Captionless MSO CommandBar !!

    How do I strip (remove) the caption of a custom CommandBar in EXCEL ?

    I know how to do that for userforms as well as other windows via setting the window Styles but can't make it work for commandbars.

    Here is what I have so far but it doesn't work !

    "Test" is the Caption of the EXCEL Custom Toolbar which is on display when the Code runs.



    Code in a Bas Module:

    VB Code:
    1. Declare Function FindWindow Lib "USER32" Alias "FindWindowA" _
    2. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3.  
    4.  
    5. Private Declare Function GetWindowLong Lib "USER32" _
    6. Alias "GetWindowLongA" (ByVal hWnd As Long, _
    7. ByVal nIndex As Long) As Long
    8.  
    9.  
    10. Private Declare Function SetWindowLong Lib "USER32" _
    11. Alias "SetWindowLongA" (ByVal hWnd As Long, _
    12. ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    13.  
    14. Private Declare Function DrawMenuBar Lib "USER32" _
    15. (ByVal hWnd As Long) As Long
    16.  
    17. Private Const GWL_STYLE As Long = (-16)
    18. Private Const WS_CAPTION As Long = &HC00000
    19.  
    20. Dim lngCBHwnd As Long
    21. Dim IStyle
    22.  
    23.  
    24. Sub Test()
    25.  
    26.     lngCBHwnd = FindWindow("MsoCommandBar", "Test")
    27.    
    28.     Debug.Print lngCBHwnd
    29.    
    30.     IStyle = GetWindowLong(lngCBHwnd, GWL_STYLE)
    31.    
    32.     IStyle = IStyle And Not WS_CAPTION
    33.    
    34.     SetWindowLong lngCBHwnd, GWL_STYLE, IStyle
    35.    
    36.     DrawMenuBar lngCBHwnd
    37.  
    38. End Sub
    Is there a special Style for these type of MSO CommandBars class ? ? Or maybe a SendMessage Function is needed with a special Msg ??


    This is driving me mad and any help would be much appreciated .

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Captionless MSO CommandBar !!

    As far as I know you can't because the caption appears to be the name of the bar, and therefore is used in the indexing/collection.

    You can create a toolbar with a space as the name.. would this help?
    Otherwise try to make the toolbar always start off attached to the menus at the top - no title is then displayed.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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

    Re: Captionless MSO CommandBar !!

    Why not use the Office Object Model to access the toolbar and remove the caption from the button(s)?

    There is no Caption property for a Toolbar but there is for a ToolbarButton.
    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

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Captionless MSO CommandBar !!

    Thanks guys but this Toolbar is meant to be dynamically attached to an Excel userform at run time that's why docking it at the top of the application window as suggested is not an answer.

    If I manage to get rid of the tollbar title bar, the toolbar buttons would look as if they were floating on top of the userform which is the visual effect I want.

    I am really desperate to make this work even if I have to create the toolbar from scrach using the API but I don't know how

    Adding button controls to the userform and copying FaceIds pictures to them as well as arranging them next to each other accross the top of the UserForm would still not be as good as having the real thing .

    Anyone knows how I can create an MSO Toolbar from scrach using the API so I can freely manipulate it and set its Caption\Title bar Window Styles among other things ??

    Anyone ? Thanks.

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

    Re: Captionless MSO CommandBar !!

    Your loosing me. You want a userform without a Titlebar but with a commandbar toolbar? Can you sketch a crude drawing?
    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

  6. #6

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    Re: Captionless MSO CommandBar !!

    Sorry for not explaining properly.

    I want to keep the UserForm Title Bar as normal but I also want to attach a Captionless Toolbar accross the top of the UserForm (ie : Just under the UserForm Title Bar).

    Thanks.

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