Word vba 获得当前表的序号

Sub 获得当前表的序号()
    
    With Selection
        If .Information(wdWithInTable) = True Then
            If .Cells.Count = 1 Then
                StrAddr = "T" & Selection.Tables(1).Range.Start & "R" & .Cells(1).RowIndex & "C" & .Cells(1).ColumnIndex
            Else
                StrAddr = "No Table Or More Tables "
            End If
        Else
            MsgBox "当前没选中表格", vbOKOnly + vbCritical, "提示"
            Exit Sub
        End If
    End With
    
    Dim tempTable As Table
    Dim i As Integer
    i = 1
    
    For Each tempTable In ActiveDocument.Tables
        tempTable.ID = i
        i = i + 1
    Next
    
    MsgBox "当前是第 " & Selection.Tables(1).ID & " 个表", vbOKOnly + vbInformation, "表格序号判断"
    
End Sub
相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页