How can I handle CustomButtonBar_Click event?

F

fausto

I have a problem...

I have created a custombar with a custombutton. I have a sub named MySub.
I set custombutton OnAction property with a value "MySub", but when I click
on it Excel give me a follow message: Impossible Locate MySub macro.

Can someone help me? Sorry for my english...

Dim cmdBars As CommandBars
Dim Bar As CommandBar
Dim btnBar As CommandBarButton
Set cmdBars = Application.CommandBars
Set Bar = cmdBars.Add
Bar.Name = "Export"
Bar.Position = msoBarTop
Bar.Visible = True
'******************************
Set btnBar = Bar.Controls.Add
btnBar.Style = msoButtonCaption
btnBar.FaceId = 2
btnBar.Caption = "Esporta"
btnBar.Width = 80
btnBar.Visible = True
btnBar.OnAction = "MySub"

Sub MySub()
'My lines of code
End Sub
 
B

Bernie Deitrick

Fausto,

Your code worked for me. You could try being more specific with your
onaction property:

btnBar.OnAction = ThisWorkbook.FullName & "!MySub"

HTH,
Bernie
MS Excel MVP
 
F

fausto

Thanks a lot for the advice Bernie, but it don't work for me...

Sorry, maybe I can be more clear.

The lines of code of my first post are into a file named Export.xla located
in C:\Documents and Settings\UserName\DatiApplicazioni\Microsoft\AddIns.
This because I want that every time I'm starting Excel with a new sheet I
can use my CustomButton for exporting data...
But if I click this message appears "Impossible Finding MySub Macro"...

Can someone suggest me an other solution for this?
 

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

Top