【发布时间】:2020-07-16 06:18:10
【问题描述】:
晚安 VBA 大师
我可以就我的代码向您寻求帮助吗?
如下所示,我的代码仅用于搜索特定标题样式的单词,然后将其转换为小写。
我的问题是,一旦我在消息框中选择“否”,我的宏就会停止在下一个标题中搜索相同的单词。
我的文档确实有多个标题,我需要搜索同一个词,直到文档的最后一个标题。
我遵循 SOP,因此无法将所有单词都转换为小写。
希望您能帮我解决我的问题。提前谢谢你。
Sub ChangeCase1()
Dim StrFind As String, StrRepl As String
Dim i As Long
StrFind = "And,Aboard,About,Above,Across,After,Against,Along,Alongside,Amid,Amidst,Among,Around,As,Aside,At,Athwart,Atop,Barring,Before,BehindBelow,Off,On,Onto,Opposite,Out,Outside,Beneath,Beside,Besides,Between,Beyond,But,By,Circa,Concerning,Despite,Down,During,Except,Following,For,From,In,Inside,Into,Like,Mid,Minus,Near,Next,Notwithstanding,Of,Worth,Over,Pace,Past,Per,Plus,Regarding,Round,Since,Than,Through,Throughout,Till,Times,To,Toward,Towards,Under,Underneath,Unlike,Until,Up,Upon,Versus,Via,With,Within,Without"
Set RngTxt = Selection.Range
For i = 0 To UBound(Split(StrFind, ","))
With Selection.Find
.ClearFormatting
.Wrap = wdFindContinue
.Forward = True
.Format = True
.MatchCase = True
.Text = Split(StrFind, ",")(i)
.Style = ActiveDocument.Styles("K-Heading Level 1")
.Execute
While .Found
If MsgBox("Replace " & Split(StrFind, ",")(i), vbYesNo) = vbYes Then
Selection.Range.Case = wdLowerCase
Selection.Collapse Direction:=wdCollapseEnd
.Execute
Else
GoTo Continue
End If
Wend
End With
Continue:
Next i
Call ChangeCase2
End Sub
【问题讨论】:
标签: vba replace ms-word lowercase