?
Solved

Error Handling in MS Word, Merged rows count issue

Posted on 2007-09-11
1
Medium Priority
?
933 Views
Last Modified: 2010-08-05
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
0
Comment
Question by:Craig Lambie
1 Comment
 
LVL 77

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 19867606
You can find the number of columns in Row 1 from the cell count.
Row1Cols = tbl.Columns(1).Cells.Count.

The reason that the error is displayed is that you enter the error handling procedure after the first occurrence of an error and never come out of it, so the second error will cause a break.
Use Resume to end error processing:

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:
    Resume ErrBack

End Function
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

568 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question