나는 3 개의 공백 중 첫 번째 공백의 형식을 바꾸기위한 매크로를 작성했으며 파란색 글꼴의 숫자가있는 특정 문자열과 괄호 안의 공백을 바꿔주는 공백을 교체하기위한 매크로를 작성했습니다. 끈.MS-Word VBA 스크립트 찾기 및 바꾸기
이 두 가지 절차를 최적화하는 방법을 알고 있습니까 (저는 검색의 와일드 카드를 사용하고 MS-Word의 대화 상자를 바꾸지 만 VBA에서 이것을 사용하는 것이 바람직하지 않습니까?).
내 매크로 :
Sub replace_3spaces()
Dim str_after As String
Dim re_number As Integer
str_after = "normal"
re_number = "1"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([^s]{3})" & "(" & str_after & ")"
.Replacement.Text = "§§§\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.Font.ColorIndex = wdBlue
With Selection.Find
.Text = "§§§"
.Replacement.Text = re_number & " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub