2016-04-26 104 views
0

我想找到一些text如果這段文字是表,則表格轉換成文本別的什麼也不做如果沒有表,然後做別的

但如果沒有Table它提供了一個Error

Selection.Find.ClearFormatting 
With Selection.Find 
    .Text = " - ^$^$^$^$ ^$ - ^$^$^$^$^$^$" 
    .Forward = True 
    .Wrap = wdFindStop 
    .Format = True 
End With 
Selection.Find.Execute 
If Selection.Find.Found = True Then 

Selection.Tables(1).Select ' This is Error position 

Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _ 
    True 

Else 
End If 

,我希望它doloop

+1

如果selection.tables.count> -0然後.....對於I = 1到selection.tables.count .. ..... –

回答

1

添加一個條件,如果Selection.Tables.Count> 0到你的代碼

Selection.Find.ClearFormatting 
    With Selection.Find 
     .Text = " - ^$^$^$^$ ^$ - ^$^$^$^$^$^$" 
     .Forward = True 
     .Wrap = wdFindStop 
     .Format = True 
    End With 
    Selection.Find.Execute 
    If Selection.Find.Found = True Then 

    If Selection.Tables.Count > 0 Then 
     Selection.Tables(1).Select ' This is Error position 

     Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:=True 
    End If 
End If 

問候。

0

@nathan_sav感謝

以下是工作代碼loop

do 
Selection.Find.ClearFormatting 
With Selection.Find 
    .Text = " - ^$^$^$^$ ^$ - ^$^$^$^$^$^$" 
    .Forward = True 
    .Wrap = wdFindStop 
    .Format = True 
End With 
Selection.Find.Execute 
If Selection.Find.Found = True Then 

if selection.tables.count>0 then 
Selection.Tables(1).Select 

Selection.Rows.ConvertToText Separator:=wdSeparateByTabs, NestedTables:= _ 
True 
else 
end if 


Else 
exit do 
End If 
loop 
相關問題