[VBA ]找到的字串跑掉了

看板Visual_Basic作者時間15年前 (2010/11/19 15:18), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
請問一下 我先用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
文章代碼(AID): #1CvYJSSD (Visual_Basic)
文章代碼(AID): #1CvYJSSD (Visual_Basic)