title: MouseMove event on dynamically created Form Control Label
body: <p>I am trying to dynamically create a shape in VBA, and then assign a mouse event to it, so that if the user moves the mouse over the shape an event will be triggered.</p>
  
  <p>I searched in this forum and elsewhere on the internet, and realized that shapes cannot have events associated. The workaround is to add a from control (like Label) on top and add an event to that.</p>
  
  <p>Since I am dynamically creating the label, I understand that I need to create a custom <code>Class</code> and define the label <code>WithEvents</code> to trigger the event. I wrote the code below, but am getting the error </p>
  
  <blockquote>
    <p>"Object does not source automation events".</p>
  </blockquote>
  
  <p>Code for Class Definition:</p>
  
  <pre><code>'Class name clsEventShape
  
  Public WithEvents evtLabel As Label
  
  Private Sub evtLabel_mousemove()
      MsgBox "Mouse Moved!!"
  End Sub
  </code></pre>
  
  <p>Code for generation of shape and label:</p>
  
  <pre><code>Option Explicit
  Option Base 1
  
  Dim Lbl As Label
  Dim evtLbl As clsEventShape
  Dim Shp As Shape
  Dim WS As Worksheet
  
  Public Sub addShape()
      WS = ActiveSheet
  
      Set Shp = WS.Shapes.addShape(msoShapeRoundedRectangle, 10, 10, 100, 100)
  
      With Shp
          .Fill.ForeColor.RGB = RGB(Rnd() * 255, Rnd() * 255, Rnd() * 255)
      End With
  
      evtLbl = New clsEventShape
      Set evtLbl.evtLabel = WS.Controls.Add("Form.Label.1")
      Set Lbl = evtLbl.evtLabel
  
      With Lbl
          .Left = 10
          .Top = 10
          .Width = 100
          .Height = 100
          .Caption = "Hello"
      End With 
  End Sub
  </code></pre>