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

4

2 回答 2

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

问候。

于 2016-04-26T12:24:48.750 回答
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
于 2016-04-26T12:29:09.473 回答