vb 查找字符串
我想在word中找到指定的字符串并读取这个字符串后面的若干字符,能不能给点提示,我这几天在用Range函数,但总是不好用,谢谢
[解决办法]
Sub find_word()
set_txt: x_text = InputBox( "请输入要查找的内容 ", "取字符串 ", "试试看 ")
If Len(x_text) < 1 Then Exit Sub
Selection.Find.ClearFormatting
With Selection.Find
.Text = x_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
If Selection.Text <> x_text Then MsgBox "对不起,没有找到符合条件的字符,请重新设置查找条件! ": GoTo set_txt
Selection.MoveRight Unit:=wdCharacter, Count:=1
set_num: xx = InputBox( "已经找到字符串,请输入你要取得的字符的个数! ", "取字符串 ", 1)
If Len(xx) < 1 Then MsgBox "您已经取消了本次操作! ": Exit Sub
If Not IsNumeric(xx) Then MsgBox "请输入数字! ": GoTo set_num
Selection.MoveRight Unit:=wdCharacter, Count:=xx, Extend:=wdExtend
MsgBox "为您提取的字符串如下: " & Chr(10) & Selection.Text
End Sub
[解决办法]
你可以用 Range 的 Start: 和 End: 指定你要的字符,用 .Text 属性取得。