Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error Handling in MS Word, Merged rows count issue

Posted on 2007-09-11
1
Medium Priority
?
905 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 76

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

927 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