Link to home
Create AccountLog in
Visual Basic.NET

Visual Basic.NET

--

Questions

--

Followers

Top Experts

Avatar of Craig Lambie
Craig Lambie🇦🇺

Error Handling in MS Word, Merged rows count issue
Hi Experts,

I have a Word Macro that I wrote that is supposed to count the number of rows in Column 1 of this table, as some are merged the usual table.rows.count doesn't work.
Any suggestions as to why I get a Debug Error when "only stop on unhandled errors" is selected at the line marked *, when I get to row 4, when in column 1 there are actually only 3 rows, due to merging.  I know why the error occurs, I don't know how to handle it so it doesn't stop.

Code:
Function fMergedRows() As String
On Error GoTo Err_handler
   
Dim tbl As Table
Dim i As Integer
Dim strComma As String
Dim strMergedRows As String

    Set tbl = ActiveDocument.Tables(1)
   
    strComma = ""
   
    For i = 1 To tbl.Rows.Count
        Debug.Print tbl.Cell(i, 1).Creator
        fMergedRows = fMergedRows & strComma & i
        strComma = ","
        Debug.Print fMergedRows
ErrBack:
    Next i
   
Exit Function
Err_handler:
    GoTo ErrBack

End Function

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of GrahamSkanGrahamSkan🇬🇧

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

Visual Basic.NET

Visual Basic.NET

--

Questions

--

Followers

Top Experts

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,