Detect first one-row-table in document and display the index number in a msgbox

Dear Experts:

I would like to run a macro with the following requirements:

Search for the first one-row table in the current document and if found display the index number in a msgbox.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
Hi Andreas,
 I'm sure that you could do this yourself, but see if this does it:
Sub FirstSingle()
    Dim tbl As Table
    Dim i As Integer
    
    For Each tbl In ActiveDocument.Tables
        i = i + 1
        If tbl.Rows.Count = 1 Then
            MsgBox "First single-row table is No: " & i
            Exit For
        End If
    Next tbl
End Sub

Open in new window

0
 
Andreas HermleTeam leaderAuthor Commented:
thank you very much for your great help. I do quite a lot of code writing myself by mostly tweaking your codes but sometimes I got stuck with even the easiest things.

Regards, Andreas
0
All Courses

From novice to tech pro — start learning today.