2011年12月11日日曜日

[ExcelVBA] TypeName関数


■構文
TypeName(varname)

■説明
変数の型を返します。
第一引数:変数を指定します。

■サンプルコード
  1. Option Explicit  
  2. Sub SampleCode()  
  3.     Dim Str1 As String  
  4.     Debug.Print TypeName(Str1) 'String  
  5.   
  6.     Dim Str2() As String  
  7.     Debug.Print TypeName(Str2) 'String() 文字列の配列  
  8.   
  9.     Dim num1 As Integer  
  10.     Debug.Print TypeName(num1) 'Integer  
  11.       
  12.     Dim num2 As Long  
  13.     Debug.Print TypeName(num2) 'Long  
  14.       
  15.     Dim yymmdd As Date  
  16.     Debug.Print TypeName(yymmdd) 'Date  
  17.       
  18.     Dim obj As Object  
  19.     Debug.Print TypeName(obj) 'Nothin (Set前)  
  20.       
  21.     Set obj = CreateObject("Scripting.Dictionary")  
  22.     Debug.Print TypeName(obj) 'Dictionary (Set後)  
  23. End Sub  

0 件のコメント: