Macro to detect whether the table has vertically merged cells beforethe actual tabel macro is execut

A

andreas

Dear Experts:

I got a table macro that applies some specific formatting to the
selected table. If the macro hits vertically merged cells I get an
error message showing "5991" as error number. But then some formatting
has already been applied.

So what I would like to get is a code snippet that before the actual
table macro is executed...
....first loops through all rows and columns of a selected table,
....detects whether there are vertically merged cells and
.... in case there are any, exits the sub before the actual table macro
is executed.


I hope I have made myself clear.

Any help would me much appreciated.

Thank you very much in advance.

Regards, Andreas
 
D

Doug Robbins - Word MVP

Maybe simpler to use UndoClear before the macro starts, then have a counter
n record the number of changes made and if the error occurs, in the error
handling routine use Undo n and then exit sub.

However, the following code will produce the error without doing anything to
the table

Dim a As Range
Dim i As Long
On Error GoTo ExitThis
With Selection.Tables(1)
For i = 1 To .Rows.Count
Set a = .Rows(i).Cells(1).Range
Next i
End With

ExitThis:
If Err.Number = 5991 Then
MsgBox "Vertically Merged Cells"
Exit Sub
End If


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

andreas

Maybe simpler to use UndoClear before the macro starts, then have a counter
n record the number of changes made and if the error occurs, in the error
handling routine use Undo n and then exit sub.

However, the following code will produce the error without doing anythingto
the table

Dim a As Range
Dim i As Long
On Error GoTo ExitThis
With Selection.Tables(1)
For i = 1 To .Rows.Count
    Set a = .Rows(i).Cells(1).Range
Next i
End With

ExitThis:
If Err.Number = 5991 Then
    MsgBox "Vertically Merged Cells"
    Exit Sub
End If

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP












- Show quoted text -

Hey Doug,

thank you very much for your terrific help. It works fine. Thank you,
Regards, Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top