Visual Basic.NET
--
Questions
--
Followers
Top Experts
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
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
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
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,