title: Determine library name of object variable in VBA 2007..?
body: <p>How can the fully qualified class and member name of an object variable be determined in VBA 2007..? For instance, <code>Excel.Range</code> rather than just <code>Range</code>...just as it appears in code?</p>
  
  <p>Both Excel and Word have a <code>Range</code> object, but they are vastly different classes. In the example below, a <code>Range</code> is passed to the function. How can the function determine which class it's from..? </p>
  
  <p>The results of the example produce "Microsoft Excel.Range". Although that's close, it's not the same. But Parent.Name and the class name are two different properties, and in other software they could be totally different text strings with no commonality.</p>
  
  <p>So...how can one get <code>Excel.Range</code> instead of <code>Microsoft Excel.Range</code>..?</p>
  
  <pre><code>'Note: Project has references to both Excel and Word.
  Public Sub Demo()
      Dim r As Excel.range
      Dim fulltype As String
      Set r = ActiveCell
      fulltype = WhatAmI(r)
      Debug.Print fulltype
      Select Case fulltype
          Case "Excel.Range"
              'Do stuff.
          Case "Word.Range"
              'Do other stuff.
      End Select
  End Sub
  
  Private Function WhatAmI(ByRef X As Object) As String
      Dim typ As String
      Dim par As String
      typ = TypeName(X)
      par = X.Application.Parent.Name
      WhatAmI = par &amp; "." &amp; typ
  End Function
  </code></pre>