0

I have menu with submenu made of control buttons:

Set MenuItem = .Controls.Add(Type:=msoControlPopup)
With MenuItem
    .caption = "Code Type"

    With .Controls.Add(Type:=msoControlButton)
        .caption = "Lists"
        .OnAction = "'" & ThisWorkbook.Name & "'!" & "setCaption"
    End With

End With

Sub setCaption()
    MsgBox Application.caller
End Sub

When I try with the above example, I get Type mismatch error.

9
  • What does MsgBox TypeName(Application.Caller) give you? Commented May 2, 2020 at 16:08
  • @MathieuGuindon it gives variant Commented May 2, 2020 at 16:29
  • Weird, TypeName returns the runtime type, that... should be the variant subtype. Does MsgBox TypeOf Application.Caller Is Object return true? The idea is to get what type the caller is, IIRC should be a CommandBarButton. Alternatively you could take a string parameter and pass it along in the OnAction string, that would be more reliable than Application.Caller IMO. Commented May 2, 2020 at 16:35
  • @MathieuGuindon MsgBox TypeOf Application.Caller Is Object gives False Commented May 2, 2020 at 16:36
  • Where's the type mismatch error being raised exactly? Commented May 2, 2020 at 16:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.