您的位置:程序门 -> vb -> vba



vb 查找字符串


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


vb 查找字符串[已结贴,结贴人:hgdszct]
发表于:2007-06-19 21:25:10 楼主
我想在word中找到指定的字符串并读取这个字符串后面的若干字符,能不能给点提示,我这几天在用range函数,但总是不好用,谢谢
发表于:2007-06-19 21:36:521楼 得分:0
查找我基本上解决了,可以用selection.find或者word.range.find,但找到后怎么找到这个字符串后面的若干字符呢
发表于:2007-06-21 08:17:122楼 得分:10
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
发表于:2007-06-21 08:23:423楼 得分:10
你可以用   range   的   start:   和   end:   指定你要的字符,用   .text   属性取得。
发表于:2007-06-21 22:35:354楼 得分:0
多谢,已解决


快速检索

最新资讯
热门点击