Description
Returns a string that provides information about a variable.
Syntax
TypeName(varname)
The varname named argument can be any variable except a variable of a user-defined type.
Remarks
The string returned by TypeName can be any one of the following:
String Returned |
Variable contains |
objecttype |
An OLE Automation object whose type is objecttype. |
Integer |
An integer. |
Long |
A long integer. |
Single |
A single-precision floating point number. |
Double |
A double-precision floating point number. |
Currency |
A currency value. |
Date |
A date. |
String |
A string. |
Boolean |
A Boolean value. |
Error |
An error value. |
Empty |
Uninitialized. |
Null |
No valid data. |
Object |
An object that doesn't support OLE Automation. |
Unknown |
An OLE Automation object whose type is unknown. |
Nothing |
An object variable that doesn't refer to an object. |
If varname is an array, the returned string can be any one of the possible returned strings (or Variant) with empty parentheses appended. For example, if varname is an array of integers, TypeName returns "Integer()".
See Also
Data Type Summary, IsArray Function, IsDate Function, IsEmpty Function, IsError Function, IsMissing Function, IsNull Function, IsNumeric Function, IsObject Function, Variant Data Type, VarType Function.
Example
This example uses the TypeName function to return information about a variable.
' Declare variables. Dim StrVar As String, IntVar As Integer, CurVar As Currency Dim ArrayVar (1 To 5) As Integer NullVar = Null ' Assign Null value. MyType = TypeName(StrVar) ' Returns "String". MyType = TypeName(IntVar) ' Returns "Integer". MyType = TypeName(CurVar) ' Returns "Currency". MyType = TypeName(NullVar) ' Returns "Null". MyType = TypeName(ArrayVar) ' Returns "Integer()".
This example displays the Visual Basic object type of the selection. You can run this example with cells selected, with a single oval selected, or with several different graphic objects selected.
Worksheets("Sheet1").Activate MsgBox "The selection object type is " & TypeName(Selection)