V
VBA Coder
How can I attach a custom command bar to a particular form using VBA? When
my UserForm loads, in my Initialize routine, I'd like to call the following
AddMenuBar subroutine that will create a temporary Command Bar for that
Form. I am able to get it to create a command bar, but can't seem to get it
associated with the form - it floats on the screen.
Private Sub AddMenuBar()
Dim customBar As CommandBar
Dim newButton As CommandBarButton
Set customBar = CommandBars.Add("Custom", , , True)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Cut").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Copy").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Paste").ID)
customBar.Visible = True
End Sub
my UserForm loads, in my Initialize routine, I'd like to call the following
AddMenuBar subroutine that will create a temporary Command Bar for that
Form. I am able to get it to create a command bar, but can't seem to get it
associated with the form - it floats on the screen.
Private Sub AddMenuBar()
Dim customBar As CommandBar
Dim newButton As CommandBarButton
Set customBar = CommandBars.Add("Custom", , , True)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Cut").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Copy").ID)
Set newButton = customBar.Controls _
.Add(msoControlButton, CommandBars("Edit") _
.Controls("Paste").ID)
customBar.Visible = True
End Sub