爱奇艺取消自动续费:关于VB中的find用法

来源:百度文库 编辑:高校问答 时间:2024/04/30 02:09:06
各位大哥好,我想替换WORD中的一些字符串,
With wordapp.Selection.find
.Text = "_"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = True
End With
wordapp.Selection.find.Execute
可这样只能替换一次,我想用个DO循环,可不知道什么可以用来作为判断量,当全部替换完后可以停止?

重载有:
public int Find(char[ ] characterSet)
public int Find(char[ ] characterSet, int start)
public int Find(char[ ] characterSet, int start, int end)
public int Find(string str)
public int Find(string str, System.Windows.Forms.RichTextBoxFinds options)
public int Find(string str, int start, System.Windows.Forms.RichTextBoxFinds options)
public int Find(string str, int start, int end, System.Windows.Forms.RichTextBoxFinds options)

characterSet和str:指要在控件中定位的文本
start:控件文本中开始搜索的位置
end:控件文本中结束搜索的位置。此值必须等于 -1 或者大于或等于 start 参数
options:System.Windows.Forms.RichTextBoxFinds 值的按位组合

一般来讲用Find(str, start, end)就行了,你使用后,如果options不为NoHighlight,就会自动在文本框中选中,然后使用richtextbox.copy即可复制

用全部替换就行了,不必用循环,也没必要判断。下面是我录制的宏:
Sub f1()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "_"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub