2016-04-26 19 views
0

tun möchte ich einige text finden, wenn dieser Text in der Tabelle ist dann die Tabelle in Text umwandeln sonst nichtsWenn es keine Tabelle dann sonst

tun, aber wenn es keine Table ist gibt es eine 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 

und ich möchte es do es in loop

+1

wenn selection.tables.count> -0 dann ..... für I = 1 bis selection.tables.count .. ..... –

Antwort

1

eine Bedingung hinzufügen, wenn Selection.Tables.Count> 0, um Ihren Code

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 

Grüße.

0

@nathan_sav dank

Nach arbeitet Code in 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 
Verwandte Themen