I try to programmatically adding a VBA button to my workbook. I can creat it but for some reason I can't link a macro on it.
I always get the error message :
Cannot run the macro "xxx". the macro may not be available in this WB or all macros may be disabled
Here is my code :
Private Sub Workbook_Open()
'Remove all old buttons of the worksheet
ActiveSheet.Buttons.Delete
'Restore Folder selector button
Set t = ActiveSheet.Range(Cells(2, 1), Cells(2, 1))
Set btn = ActiveSheet.Buttons.Add(t.Left, t.Top, t.Width, t.Height)
With btn
.OnAction = "FolderSelector"
.Caption = "Folder selector"
.Name = "Folder Selector"
End With
End Sub
Sub FolderSelector()
MsgBox Application.Caller
End Sub
Is there anyone know what's wrong ?