Solved VBA code to show a custom toolbar

Capitala

Member
Local time
Today, 17:17
Joined
Oct 21, 2021
Messages
78
Good day!
Please! I'm using word 2003. I need a vba code to show a custom toolbar.
Thnaks
 
From chatgpt. For you to test. I do not have word 2003.

Code:
Sub ShowMyCustomToolbar()
    Dim myToolbar As CommandBar

    On Error Resume Next
    Set myToolbar = CommandBars("My Custom Toolbar")
    On Error GoTo 0

    If myToolbar Is Nothing Then
        ' Create the toolbar
        Set myToolbar = CommandBars.Add(Name:="My Custom Toolbar", Position:=msoBarTop, Temporary:=True)
       
        ' Add a sample button to the toolbar
        With myToolbar.Controls.Add(Type:=msoControlButton)
            .Caption = "My Button"
            .Style = msoButtonCaption
            .OnAction = "MyButtonMacro"
        End With
    End If

    ' Show the toolbar
    myToolbar.Visible = True
End Sub

Sub MyButtonMacro()
    MsgBox "You clicked the button!"
End Sub
How to use:
Open Word 2003.

Press Alt + F11 to open the VBA Editor.

Insert a new module (Insert > Module).

Paste the code above into the module.

Run the ShowMyCustomToolbar macro (F5 or run from the macro dialog).

Edit: No need to say 'Thaaaaaaaaaaaaaaaanks' :)
 

Users who are viewing this thread

Back
Top Bottom