【发布时间】:2015-09-24 16:33:18
【问题描述】:
我想找一个里面有蓝色文字的句子,选中整个句子,把蓝色的字一个一个去掉。我的代码只删除了句子中的第一个蓝色单词,然后才转到 With 语句。
我正在寻找类似这样的伪代码:
而 objSelectionChange.Sentences(1).Find.Font.Color = wdColorBlue
对于当前选定的句子,这将是一个嵌套的 while 循环
Do While True
objSelectionChange.Find.Forward = True
objSelectionChange.Find.Format = True
objSelectionChange.Find.Font.Color = wdColorBlue
objSelectionChange.Find.Execute
If objSelectionChange.Find.Found Then
strg2 = objSelectionChange.Sentences(1).Text
count = count + 1
ReDim strgArray(count)
strgArray(count) = objSelectionChange.Text
MsgBox strgArray(count) & " Located In Array Index # " & count
MsgBox strg2
strg3 = Replace(strg2, strgArray(count), "")
strg3 = Replace(strg3, " ", " ")
strg3 = Mid(strg3, 1, Len(strg3) - 2)
MsgBox strg3
Else
Exit Do
End If
Set objRangeOrig = objDocOrig.Content
'''''Search the string in the original manual'''''
With objRangeOrig.Find
.MatchWholeWord = False
.MatchCase = False
.MatchPhrase = True
.IgnoreSpace = True
.IgnorePunct = True
.Wrap = wdFindContinue
.Text = strg3
.Replacement.Text = Left(strg2, Len(strg2) - 2)
.Execute Replace:=wdReplaceOne
End With
Loop
【问题讨论】:
标签: vba loops ms-word do-while