2016-04-26 8 views
0

Je veux trouver un text si ce texte est dans le tableau, puis convertir la table en texte d'autre ne rienS'il n'y a pas de table puis faire autre

Mais quand il n'y a pas Table il donne une 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 

et je veux qu'il do dans loop

+1

si selection.tables.count> -0 puis ..... pour I = 1 à selection.tables.count .. ..... –

Répondre

1

Ajouter une condition, si Selection.Tables.Count> 0 à votre 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 

Cordialement.

0

@nathan_sav grâce

trouverez ci-dessous le code de travail dans 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