Skip to content

Instantly share code, notes, and snippets.

@AWtnb
Created May 20, 2024 06:48
Show Gist options
  • Save AWtnb/421c63e404c77021534082d129b92aba to your computer and use it in GitHub Desktop.
Save AWtnb/421c63e404c77021534082d129b92aba to your computer and use it in GitHub Desktop.
Word VBA 全角数字を半角に一括変換
Sub 全角数字を半角にする()
If Selection.Type = wdSelectionIP Then
MsgBox "範囲選択して下さい"
Exit Sub
End If
Dim i As Integer
Application.ScreenUpdating = False
For i = 0 To 9
With Selection.Find
.Text = StrConv(i, vbWide) '検索する文字列
.Replacement.Text = i '置換後の文字列
.Forward = True
.Wrap = wdFindStop
.Format = False '書式の設定をオン
.MatchCase = False '大文字と小文字の区別する
.MatchWholeWord = False '完全に一致する単語だけを検索する
.MatchAllWordForms = False '英単語の異なる活用形を検索する
.MatchSoundsLike = False 'あいまい検索(英)
.MatchFuzzy = False 'あいまい検索(日)
.MatchWildcards = False 'ワイルドカードを使用する
.MatchByte = True '半角と全角を区別する
.Execute Replace:=wdReplaceAll
DoEvents
End With
Next i
'画面更新をオン
Application.ScreenUpdating = True
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment