【问题标题】:If there is no Table then do else如果没有表,则执行其他操作
【发布时间】:2016-08-20 06:15:10
【问题描述】:

我想找一些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

我希望它在 loopdo

【问题讨论】:

  • if selection.tables.count>-0 then..... for I =1 to selection.tables.count ....

标签: vba ms-word word-2007 word-2003


【解决方案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

问候。

【讨论】:

    【解决方案2】:

    @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
    

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 2022-01-12
      • 2016-11-26
      • 2014-11-04
      • 1970-01-01
      • 2016-03-24
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多