how to Add a command button to the standard commandbar of the visual editor window

  • Thread starter Thread starter MichDenis
  • Start date Start date
M

MichDenis

Hi,

This code add a button to the "standard" command bar of the
visual editor window ?

Does someone know why it does not work ?
and what to change to make it work.

'---------------------
Sub Test()

With ThisWorkbook.VBProject.VBE.CommandBars("Standard")
With .Controls.Add(msoControlButton)
.Style = msoButtonWrapCaption
.Caption = "Recherche"
.OnAction = "Module5.test1"
End With
End With

End Sub

'---------------------
Sub test1()
MsgBox "Good afternoon"
End Sub
'---------------------

Thank in advance for you time.

Salutations
 
Not absolutely sure, but pretty sure you didn't need the second With statment.

Sub Test()
With ThisWorkbook.VBProject.VBE.CommandBars("Standard").Controls.Add
_(msoControlButton)
.Style = msoButtonWrapCaption
.Caption = "Recherche"
.OnAction = "Module5.test1"
End With
End Sub

I haven't tried adding anything in the VBE before, but it shouldn't be a lot
different that adding to an Excel menu bar.
 
After checking some of the help files, it looks like you will need to use the
Set statement to get this to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top