Created
April 14, 2013 15:25
-
-
Save nozma/5383099 to your computer and use it in GitHub Desktop.
Emacs風キーバインド in WordVBA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'' ----- Emacsモードの有効化と無効化 --------------------- | |
Sub EnableEmacsMode() | |
Call AddKeyBindings("ForwardChar", wdKeyControl + wdKeyF) | |
Call AddKeyBindings("BackwardChar", wdKeyControl + wdKeyB) | |
Call AddKeyBindings("NextLine", wdKeyControl + wdKeyN) | |
Call AddKeyBindings("PreviousLine", wdKeyControl + wdKeyP) | |
Call AddKeyBindings("BeginningOfLine", wdKeyControl + wdKeyA) | |
Call AddKeyBindings("EndOfLine", wdKeyControl + wdKeyE) | |
End Sub | |
Sub DisableEmacsMode() | |
Call DeleteKeyBindings(wdKeyControl + wdKeyF) | |
Call DeleteKeyBindings(wdKeyControl + wdKeyB) | |
Call DeleteKeyBindings(wdKeyControl + wdKeyN) | |
Call DeleteKeyBindings(wdKeyControl + wdKeyP) | |
Call DeleteKeyBindings(wdKeyControl + wdKeyA) | |
Call DeleteKeyBindings(wdKeyControl + wdKeyE) | |
End Sub | |
Sub AddKeyBindings(Command As String, KeyCode As Long) | |
'' キーバインド登録 | |
Application.KeyBindings.Add _ | |
KeyCategory:=wdKeyCategoryCommand, _ | |
Command:=Command, KeyCode:=KeyCode | |
End Sub | |
Sub DeleteKeyBindings(KeyCode As Long) | |
'' キーバインド登録解除 | |
With Application.FindKey(KeyCode) | |
.Disable: .Clear | |
End With | |
End Sub | |
'' ------ キーバインドマクロ定義 ------------------------ | |
Sub ForwardChar() '' カーソル前移動 | |
Selection.MoveRight unit:=wdCharacter, Count:=1 | |
End Sub | |
Sub BackwardChar() '' カーソル後ろ移動 | |
Selection.MoveLeft unit:=wdCharacter, Count:=1 | |
End Sub | |
Sub NextLine() '' カーソル下移動 | |
Selection.MoveDown unit:=wdLine, Count:=1 | |
End Sub | |
Sub PreviousLine() '' カーソル上移動 | |
Selection.MoveUp unit:=wdLine, Count:=1 | |
End Sub | |
Sub BeginningOfLine() '' 行頭へ | |
Selection.HomeKey unit:=wdLine | |
End Sub | |
Sub EndOfLine() '' 行末へ | |
Selection.EndKey unit:=wdLine | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment