[VBA ]找到的字串跑掉了
※ [本文轉錄自 Visual_Basic 看板 #1CvYJSSD ]
作者: 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
--
http://supershingetter.pixnet.net 千千靜思語
http://vipshop.pixnet.net vip
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.181.164
→
11/19 22:33, , 1F
11/19 22:33, 1F
→
11/20 00:22, , 2F
11/20 00:22, 2F
Office 近期熱門文章
PTT數位生活區 即時熱門文章