VBAで国別コードを国名に変換する方法
2文字による国名コードを入力すると国名を返却するプログラムを作成する。
サンプルコード
'ISO 3166-1 alpha-2を国名に変換する Sub 国名コードを国名に変換する() Dim countryName As String Dim countryCode As String countryCode = InputBox("国名コードを入力してください", _ "国名コードを国名に変換する", "JP") Select Case countryCode Case "IS" countryName = "アイスランド" Case "IE" countryName = "アイルランド" Case "AZ" countryName = "アゼルバイジャン" Case "AF" countryName = "アフガニスタン" Case "US" countryName = "アメリカ合衆国" Case "VI" countryName = "アメリカ領ヴァージン諸島" Case "AS" countryName = "アメリカ領サモア" Case "AE" countryName = "アラブ首長国連邦" Case "DZ" countryName = "アルジェリア" Case "AR" countryName = "アルゼンチン" Case "AW" countryName = "アルバ" Case "AL" countryName = "アルバニア" Case "AM" countryName = "アルメニア" Case "AI" countryName = "アンギラ" Case "AO" countryName = "アンゴラ" Case "AG" countryName = "アンティグア・バーブーダ" Case "AD" countryName = "アンドラ" Case "YE" countryName = "イエメン" Case "GB" countryName = "イギリス" Case "IO" countryName = "イギリス領インド洋地域" Case "VG" countryName = "イギリス領ヴァージン諸島" Case "IL" countryName = "イスラエル" Case "IT" countryName = "イタリア" Case "IQ" countryName = "イラク" Case "IR" countryName = "イラン・イスラム共和国" Case "IN" countryName = "インド" Case "ID" countryName = "インドネシア" Case "WF" countryName = "ウォリス・フツナ" Case "UG" countryName = "ウガンダ" Case "UA" countryName = "ウクライナ" Case "UZ" countryName = "ウズベキスタン" Case "UY" countryName = "ウルグアイ" Case "EC" countryName = "エクアドル" Case "EG" countryName = "エジプト" Case "EE" countryName = "エストニア" Case "SZ" countryName = "エスワティニ" Case "ET" countryName = "エチオピア" Case "ER" countryName = "エリトリア" Case "SV" countryName = "エルサルバドル" Case "AU" countryName = "オーストラリア" Case "AT" countryName = "オーストリア" Case "AX" countryName = "オーランド諸島" Case "OM" countryName = "オマーン" Case "NL" countryName = "オランダ" Case "GH" countryName = "ガーナ" Case "CV" countryName = "カーボベルデ" Case "GG" countryName = "ガーンジー" Case "GY" countryName = "ガイアナ" Case "KZ" countryName = "カザフスタン" Case "QA" countryName = "カタール" Case "UM" countryName = "合衆国領有小離島" Case "CA" countryName = "カナダ" Case "GA" countryName = "ガボン" Case "CM" countryName = "カメルーン" Case "GM" countryName = "ガンビア" Case "KH" countryName = "カンボジア" Case "MK" countryName = "北マケドニア" Case "MP" countryName = "北マリアナ諸島" Case "GN" countryName = "ギニア" Case "GW" countryName = "ギニアビサウ" Case "CY" countryName = "キプロス" Case "CU" countryName = "キューバ" Case "CW" countryName = "キュラソー" Case "GR" countryName = "ギリシャ" Case "KI" countryName = "キリバス" Case "KG" countryName = "キルギス" Case "GT" countryName = "グアテマラ" Case "GP" countryName = "グアドループ" Case "GU" countryName = "グアム" Case "KW" countryName = "クウェート" Case "CK" countryName = "クック諸島" Case "GL" countryName = "グリーンランド" Case "CX" countryName = "クリスマス島" Case "GD" countryName = "グレナダ" Case "HR" countryName = "クロアチア" Case "KY" countryName = "ケイマン諸島" Case "KE" countryName = "ケニア" Case "CI" countryName = "コートジボワール" Case "CC" countryName = "ココス(キーリング)諸島" Case "CR" countryName = "コスタリカ" Case "KM" countryName = "コモロ" Case "CO" countryName = "コロンビア" Case "CG" countryName = "コンゴ共和国" Case "CD" countryName = "コンゴ民主共和国" Case "SA" countryName = "サウジアラビア" Case "GS" countryName = "サウスジョージア・サウスサンドウィッチ諸島" Case "WS" countryName = "サモア" Case "ST" countryName = "サントメ・プリンシペ" Case "BL" countryName = "サン・バルテルミー" Case "ZM" countryName = "ザンビア" Case "PM" countryName = "サンピエール島・ミクロン島" Case "SM" countryName = "サンマリノ" Case "MF" countryName = "サン・マルタン(フランス領)" Case "SL" countryName = "シエラレオネ" Case "DJ" countryName = "ジブチ" Case "GI" countryName = "ジブラルタル" Case "JE" countryName = "ジャージー" Case "JM" countryName = "ジャマイカ" Case "GE" countryName = "ジョージア" Case "SY" countryName = "シリア・アラブ共和国" Case "SG" countryName = "シンガポール" Case "SX" countryName = "シント・マールテン(オランダ領)" Case "ZW" countryName = "ジンバブエ" Case "CH" countryName = "スイス" Case "SE" countryName = "スウェーデン" Case "SD" countryName = "スーダン" Case "SJ" countryName = "スヴァールバル諸島およびヤンマイエン島" Case "ES" countryName = "スペイン" Case "SR" countryName = "スリナム" Case "LK" countryName = "スリランカ" Case "SK" countryName = "スロバキア" Case "SI" countryName = "スロベニア" Case "SC" countryName = "セーシェル" Case "GQ" countryName = "赤道ギニア" Case "SN" countryName = "セネガル" Case "RS" countryName = "セルビア" Case "KN" countryName = "セントクリストファー・ネイビス" Case "VC" countryName = "セントビンセントおよびグレナディーン諸島" Case "SH" countryName = "セントヘレナ・アセンションおよびトリスタンダクーニャ" Case "LC" countryName = "セントルシア" Case "SO" countryName = "ソマリア" Case "SB" countryName = "ソロモン諸島" Case "TC" countryName = "タークス・カイコス諸島" Case "TH" countryName = "タイ" Case "KR" countryName = "大韓民国" Case "TW" countryName = "中国台湾省(中華民国)" Case "TJ" countryName = "タジキスタン" Case "TZ" countryName = "タンザニア" Case "CZ" countryName = "チェコ" Case "TD" countryName = "チャド" Case "CF" countryName = "中央アフリカ共和国" Case "CN" countryName = "中華人民共和国" Case "TN" countryName = "チュニジア" Case "KP" countryName = "朝鮮民主主義人民共和国" Case "CL" countryName = "チリ" Case "TV" countryName = "ツバル" Case "DK" countryName = "デンマーク" Case "DE" countryName = "ドイツ" Case "TG" countryName = "トーゴ" Case "TK" countryName = "トケラウ" Case "DO" countryName = "ドミニカ共和国" Case "DM" countryName = "ドミニカ国" Case "TT" countryName = "トリニダード・トバゴ" Case "TM" countryName = "トルクメニスタン" Case "TR" countryName = "トルコ" Case "TO" countryName = "トンガ" Case "NG" countryName = "ナイジェリア" Case "NR" countryName = "ナウル" Case "NA" countryName = "ナミビア" Case "AQ" countryName = "南極" Case "NU" countryName = "ニウエ" Case "NI" countryName = "ニカラグア" Case "NE" countryName = "ニジェール" Case "JP" countryName = "日本" Case "EH" countryName = "西サハラ" Case "NC" countryName = "ニューカレドニア" Case "NZ" countryName = "ニュージーランド" Case "NP" countryName = "ネパール" Case "NF" countryName = "ノーフォーク島" Case "NO" countryName = "ノルウェー" Case "HM" countryName = "ハード島とマクドナルド諸島" Case "BH" countryName = "バーレーン" Case "HT" countryName = "ハイチ" Case "PK" countryName = "パキスタン" Case "VA" countryName = "バチカン市国" Case "PA" countryName = "パナマ" Case "VU" countryName = "バヌアツ" Case "BS" countryName = "バハマ" Case "PG" countryName = "パプアニューギニア" Case "BM" countryName = "バミューダ" Case "PW" countryName = "パラオ" Case "PY" countryName = "パラグアイ" Case "BB" countryName = "バルバドス" Case "PS" countryName = "パレスチナ" Case "HU" countryName = "ハンガリー" Case "BD" countryName = "バングラデシュ" Case "TL" countryName = "東ティモール" Case "PN" countryName = "ピトケアン" Case "FJ" countryName = "フィジー" Case "PH" countryName = "フィリピン" Case "FI" countryName = "フィンランド" Case "BT" countryName = "ブータン" Case "BV" countryName = "ブーベ島" Case "PR" countryName = "プエルトリコ" Case "FO" countryName = "フェロー諸島" Case "FK" countryName = "フォークランド(マルビナス)諸島" Case "BR" countryName = "ブラジル" Case "FR" countryName = "フランス" Case "GF" countryName = "フランス領ギアナ" Case "PF" countryName = "フランス領ポリネシア" Case "TF" countryName = "フランス領南方・南極地域" Case "BG" countryName = "ブルガリア" Case "BF" countryName = "ブルキナファソ" Case "BN" countryName = "ブルネイ・ダルサラーム" Case "BI" countryName = "ブルンジ" Case "VN" countryName = "ベトナム" Case "BJ" countryName = "ベナン" Case "VE" countryName = "ベネズエラ・ボリバル共和国" Case "BY" countryName = "ベラルーシ" Case "BZ" countryName = "ベリーズ" Case "PE" countryName = "ペルー" Case "BE" countryName = "ベルギー" Case "PL" countryName = "ポーランド" Case "BA" countryName = "ボスニア・ヘルツェゴビナ" Case "BW" countryName = "ボツワナ" Case "BQ" countryName = "ボネール、シント・ユースタティウスおよびサバ" Case "BO" countryName = "ボリビア多民族国" Case "PT" countryName = "ポルトガル" Case "HK" countryName = "香港" Case "HN" countryName = "ホンジュラス" Case "MH" countryName = "マーシャル諸島" Case "MO" countryName = "マカオ" Case "MG" countryName = "マダガスカル" Case "YT" countryName = "マヨット" Case "MW" countryName = "マラウイ" Case "ML" countryName = "マリ" Case "MT" countryName = "マルタ" Case "MQ" countryName = "マルティニーク" Case "MY" countryName = "マレーシア" Case "IM" countryName = "マン島" Case "FM" countryName = "ミクロネシア連邦" Case "ZA" countryName = "南アフリカ" Case "SS" countryName = "南スーダン" Case "MM" countryName = "ミャンマー" Case "MX" countryName = "メキシコ" Case "MU" countryName = "モーリシャス" Case "MR" countryName = "モーリタニア" Case "MZ" countryName = "モザンビーク" Case "MC" countryName = "モナコ" Case "MV" countryName = "モルディブ" Case "MD" countryName = "モルドバ共和国" Case "MA" countryName = "モロッコ" Case "MN" countryName = "モンゴル" Case "ME" countryName = "モンテネグロ" Case "MS" countryName = "モントセラト" Case "JO" countryName = "ヨルダン" Case "LA" countryName = "ラオス人民民主共和国" Case "LV" countryName = "ラトビア" Case "LT" countryName = "リトアニア" Case "LY" countryName = "リビア" Case "LI" countryName = "リヒテンシュタイン" Case "LR" countryName = "リベリア" Case "RO" countryName = "ルーマニア" Case "LU" countryName = "ルクセンブルク" Case "RW" countryName = "ルワンダ" Case "LS" countryName = "レソト" Case "LB" countryName = "レバノン" Case "RE" countryName = "レユニオン" Case "RU" countryName = "ロシア連邦" End Select MsgBox (countryName) End Sub
変換表
参考資料として以下のサイトを参考にしました。
・wiki
コメント