文字の種類を取得
文字コードがシフトJISの場合に限りますが、以下のサンプルでは指定した文字がどのような種類なのかを取得します。
Option Explicit
MsgBox fnGetCharType("あ")
MsgBox fnGetCharType("ア")
MsgBox fnGetCharType("A")
Function fnGetCharType(strChar)
Dim strCharCode
Dim strType
fnGetCharType = "****"
If strChar = "" Then
Exit Function
End If
strType = ""
strCharCode = Right("0000" & HEX(Asc(strChar)),4)
If strCharCode <= "001F" Then '制御文字
strType = "CTRL"
ElseIf strCharCode <= "002F" Then '半角特殊文字
strType = "1SPC"
ElseIf strCharCode <= "0039" Then '半角数値
strType = "1NUM"
ElseIf strCharCode <= "0040" Then '半角特殊文字2
strType = "1SPC"
ElseIf strCharCode <= "005A" Then '半角英語
strType = "1ALP"
ElseIf strCharCode <= "0060" Then '半角特殊文字3
strType = "1SPC"
ElseIf strCharCode <= "007A" Then '半角英語
strType = "1ALP"
ElseIf strCharCode <= "007E" Then '半角特殊文字4
strType = "1SPC"
ElseIf strCharCode <= "007F" Then '制御文字2
strType = "CTRL"
ElseIf strCharCode <= "00A5" Then '半角特殊文字5
strType = "1SPC"
ElseIf strCharCode <= "00DF" Then '半角カタカナ
strType = "1KTA"
ElseIf strCharCode <= "00FF" Then '半角特殊文字6
strType = "1SPC"
ElseIf strCharCode >= "8140" And strCharCode <= "81FC" Then '全角記号
strType = "2SPC"
ElseIf strCharCode >= "824F" And strCharCode <= "8258" Then '全角数字
strType = "2NUM"
ElseIf strCharCode >= "8260" And strCharCode <= "829A" Then '全角英語
strType = "2ALP"
ElseIf strCharCode >= "829F" And strCharCode <= "82F1" Then '全角ひらがな
strType = "2HRA"
ElseIf strCharCode >= "8340" And strCharCode <= "8396" Then '全角カタカナ
strType = "2KTA"
ElseIf strCharCode >= "839F" And strCharCode <= "83D5" Then '全角ギリシャ
strType = "2GRE"
ElseIf strCharCode >= "8440" And strCharCode <= "8491" Then '全角ロシア
strType = "2RUS"
ElseIf strCharCode >= "84AF" And strCharCode <= "879C" Then '全角特殊文字
strType = "2SPC"
ElseIf strCharCode >= "889F" And strCharCode <= "9872" Then '第1水準漢字
strType = "2KNJ"
ElseIf strCharCode >= "989F" And strCharCode <= "EAA4" Then '第2水準漢字
strType = "2KNJ"
ElseIf strCharCode >= "ED40" And strCharCode <= "EEFC" Then 'NEC選定IBM拡張文字
strType = "2KNJ"
ElseIf strCharCode >= "FA40" And strCharCode <= "FC4B" Then 'IBM拡張文字
strType = "2KNJ"
ElseIf strCharCode >= "****" And strCharCode <= "****" Then '
strType = "****"
End If
fnGetCharType = strType
End Function