Scusate se insisto sull'argomento…
non riesco a capire perché mi restituisce l'errore di Run-time 5 nel seguente codice alla chiamata indicata con (*):
Sub menu1()
Public Const Mname As String = "MenuPopup"
Dim cbar As CommandBarPopup
Dim cb As CommandBar
Dim x As Long, y As Long
x = StX
y = StY
Call DeletePopUpMenu
If CBRexist(Mname) = False Then
Set cb = Application.CommandBars.Add(Name:="Mname", Position:=msoBarPopup, Temporary:=True) '(*)
Set cbar = cb.Controls.Add(Type:=msoControlButton)
With cbar
.Caption = "Item11"
End With
Set cbar = cb.Controls.Add(Type:=msoControlButton)
With cbar
.Caption = "Item12"
End With
End If
On Error Resume Next
Application.CommandBars(Mname).ShowPopup x, y
On Error GoTo 0
End Sub
Private Function CBRexist(NomeCBR As String) As Boolean
On Error Resume Next
Dim varName As Variant
varName = Application.CommandBars(NomeCBR).Name
CBRexist = Err.Number = 0
End Function
Sub DeletePopUpMenu() 'cancella il popup se già esiste
On Error Resume Next
Application.CommandBars(Mname).Delete
On Error GoTo 0
End Sub
grazie.