2016-08-17 28 views
1

我需要選擇特定的內容在MS Word 2013年每個段落我嘗試使用VBA腳本,以選擇內容..如何在word vba腳本中選擇一個特定的字符串?

Sub RepalaceStrong() 
    Selection.Find.ClearFormatting 
    Selection.Find.Replacement.ClearFormatting 
    With Selection.Find 
     .Text = "<Strong" 
     .Forward = True 
     .Wrap = wdFindContinue 
     .Format = False 
     .MatchCase = False 
     .MatchWholeWord = False 
     .MatchWildcards = False 
     .MatchSoundsLike = False 
     .MatchAllWordForms = False 
    End With 
    Selection.Extend 
    With Selection.Find 
     .Text = "</Strong>" 
     .Forward = True 
     .Wrap = wdFindContinue 
     .Format = False 
     .MatchCase = False 
     .MatchWholeWord = False 
     .MatchWildcards = False 
     .MatchSoundsLike = False 
     .MatchAllWordForms = False 
    End With 
End Sub 

但我想這個代碼,我不能逐一選擇文本。

輸入:

In general, a vector field is a function whose domain is a set of points in <Strong> a vector field is </Strong> a vector field is <Strong>function</Strong> whose domain is a set of points 

>In general, a vector field is a function whose <Strong>domain</Strong> is a set of points 

是否有可能選擇一個個都是強大的元素...

回答

0

您需要指定正確的字體在您的查找操作格式化(注意.Font.Bold = True部分下面):

With Selection.Find 
    .ClearFormatting 
    .Font.Bold = True 
    .Replacement.ClearFormatting 
    .text = "" 
    .Forward = True 
    .Wrap = wdFindContinue 
    .Format = True 
    .MatchCase = False 
    .MatchWholeWord = False 
    .MatchWildcards = False 
    .MatchSoundsLike = False 
    .MatchAllWordForms = False 
End With 

然後,當然,這取決於你想用粗體文本做什麼。目前上面的代碼只是配置Find對象來搜索粗體文本。

0

這不是你正在尋找強烈,這是Font.Bold

​​
0

我答:

Sub RepalaceStrong() 
    Selection.Find.ClearFormatting 
    Selection.Find.Replacement.ClearFormatting 
    With Selection.Find 
     .Text = "<Strong" 
     .Forward = True 
     .Wrap = wdFindContinue 
     .Format = False 
     .MatchCase = False 
     .MatchWholeWord = False 
     .MatchWildcards = False 
     .MatchSoundsLike = False 
     .MatchAllWordForms = False 
    End With 
    Selection.Find.Execute 
    Selection.Extend 

    With Selection.Find 
     .Text = "</Strong>" 
     .Forward = True 
     .Wrap = wdFindContinue 
     .Format = False 
     .MatchCase = False 
     .MatchWholeWord = False 
     .MatchWildcards = False 
     .MatchSoundsLike = False 
     .MatchAllWordForms = False 
    End With 
Selection.Find.Execute 
Selection.Collapse Direction:=wdCollapseEnd 
End Sub 

我知道了....

相關問題