0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

excel アドイン向けマクロ(5)選択範囲のIMEを無効化するマクロ EXCEL VBA for Addin "Japanes IME OFF"

Last updated at Posted at 2017-03-09

まずマクロ用アドインを作ります

作り方はこちらを参照
http://hamachan.info/win8/excel/addin.html
クイックアクセスツールバーに追加することでアドインのマクロが使えるようになります。

今回は選択した範囲のIMEをOFFにして数値入力の時に不用意にIMEが起動しなくなります。

注意点

これは入力規則を使っていますので、入力規則を削除してから設定します。
なので1から入力しているときは使えますが、もうフォーマットが決まっているようなときは使わない方がいいと思います。
というのもVBAで設定する場合、入力規則は1度削除してから設定することが基本で、IMEだけ部分的に変更すると不安定になるためです。

ソース

Private Sub SetIMEModeOff()
'Data validation データの入力規則
'This Macro can run Language Setting is Japanese or Incluede Japanese
'This Macro is for Excel Addin
'https://www.moug.net/tech/exvba/0050121.html
'https://msdn.microsoft.com/ja-jp/library/office/ff193613.aspx
'http://www.atmarkit.co.jp/ait/articles/0709/14/news139.html
'http://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q1349164828?__ysp=eGxJTUVNb2RlT2Zm
'Excel.XlIMEMode
'Const xlIMEModeAlpha = 8
'Const xlIMEModeAlphaFull = 7
'Const xlIMEModeDisable = 3          <-Manual IMEMode On is imopossible
'Const xlIMEModeHangul = 10          <-If Langage Setting is Korea or Included it Then Error
'Const xlIMEModeHangulFull = 9       <-If Langage Setting is Korea or Included it Then Error
'Const xlIMEModeHiragana = 4
'Const xlIMEModeKatakana = 5
'Const xlIMEModeKatakanaHalf = 6
'Const xlIMEModeNoControl = 0         < -Default
'Const xlIMEModeOff = 2               < -This Macro Change IMEMode to it
'Const xlIMEModeOn = 1
Dim rng As Range
For Each rng In Selection
With rng.Validation
.Delete
.Add Type:=xlValidateInputOnly
.IMEMode = xlIMEModeOff
End With
Next

End Sub

このマクロは日本語設定か、日本語がインストールかなされていないとこれは動かない。
そして、いままで不安定だったが知恵袋によると
With rng.Validation
.Delete
.Add Type:=xlValidateInputOnly
.IMEMode = xlIMEModeOff
End With
この太字の部分が必要らしい。確かに安定して動くようだ。
単純に

With rng.Validation
.Delete
.IMEMode = xlIMEModeOff
End With


With rng.Validation
.IMEMode = xlIMEModeOff
End With

ではエラーになったりする。これがなぜかは謎だ。

Excel.XlIMEMode

しかしこの定数、実はハングルも入っている。ハングルにも全角と半角があるんですね。ハングルも韓国語設定か、韓国語がインストールされていないと動かない。
Const xlIMEModeHangul = 10
Const xlIMEModeHangulFull = 9
しかもここからすると全角のハングルと半角のハングルがあることに。でも調べても日本語ソースはあまりないようだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?