作者markchen ()
看板Visual_Basic
标题[VBA ]找到的字串跑掉了
时间Fri Nov 19 15:18:48 2010
请问一下
我先用find 的功能在一个内文里找到一个<test>的字串
With Selection.Find
.Text = "<test>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = False
End With
If Selection.Find.Execute(Selection.Find.Text) = True Then
Selection.Copy
Set findText = Selection.Range <--指定 这时findText的值还是<test>
End If
With Selection.Find
.Text = "<test>"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
这时findText的值清空了 是因为原本指定Range被清掉的原因吗?
我要如何一直findText的<test>给保留呢?
我想
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = "<This>"
.Replacement.Text = "<This>" + findText '<--配合上面的式子显示出
.Forward = True '<This><test> <--这里会有问题
.Wrap = wdFindContinue '因为findText的值被清掉了
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.CorrectHangulEndings = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchFuzzy = False
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
可以请各位大大指导一下小弟吗?
--
================================格斗擂台=======================================
http://myurl.com.tw/rpm8 贝德卡玛 vs 发电机(拥有十级功力)
http://myurl.com.tw/of28 贝德卡玛 vs 希斯科(芝加哥庄脚的街头混混)
http://myurl.com.tw/r40p 贝德卡玛 vs 影武者(死亡训綀!)
===============================================================================
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.134.181.164
※ markchen:转录至看板 Office 11/19 15:19