2015-11-17 42 views
0

我試圖用帶編號的空白替換具有帶下劃線的文本的所有實例。出於某種原因,以下給我溢出錯誤:字2010宏以自動遞增的文本替換帶下劃線的文本

Sub gapNumber() 
Dim myNumber As Integer 
gapCount = 1 

With ActiveDocument.Content.find 
    .ClearFormatting 
    .Font.Underline = True 
    Do While .Execute(_ 
     replace:=wdReplaceOne, _ 
     ReplaceWith:="(" & gapCount & ")", _ 
     Forward:=True) = True 

     gapCount = gapCount + 1 

    Loop 
End With 
End Sub 

我錯過了什麼?

回答

0

你什麼也沒有丟失。 我認爲方法執行中的錯誤在哪裏! 糾正無限循環其中一種方法是在更換時更改font.underline = false:

Do While .Execute(_ 
    Replace:=wdReplaceOne, _ 
    ReplaceWith:="(" & gapcount & ")", _ 
    Forward:=True) 
.Replacement.Font.Underline = False 
    gapcount = gapcount + 1 

Loop