putilkin was telling us:
putilkin nous racontait que :
How can i find merged cells in word2003? How can i find if it is
vertically or horizont. merged? When word exports to html it
specifies merged cells correctly (rowspan or colspan) but nothing
like that can be found in word itself (in cell object etc.).
Working with merged cells in VBA is very arduous and unreliable.
You can detect if there are merged cells in a table with something like:
'_______________________________________
Dim lngRowID As Long
Dim lngColID As Long
Dim tblCurrent As Table
Dim boolNoError As Boolean
Set tblCurrent = Selection.Tables(1)
boolNoError = True
If Selection.Information(wdWithInTable) Then
With tblCurrent
On Error GoTo ErrHandle
lngRowID = Selection.Rows(1).Index
lngColID = Selection.Columns(1).Index
On Error GoTo 0
End With
Else
MsgBox "Place the cursor in a table."
End If
If boolNoError Then
MsgBox "There no merged cells in this table." _
, vbInformation, "No merged cells"
End If
Exit Sub
ErrHandle:
Select Case Err.Number
Case 5991
MsgBox "There are vertically merged cells in this table." _
, vbCritical, "Error"
boolNoError = False
Case 5992
MsgBox "There are horizontally merged cells in this table." _
, vbCritical, "Error"
boolNoError = False
Case Else
MsgBox Err.Description _
, vbCritical, "Error"
Err.Clear
Exit Sub
End Select
Err.Clear
Resume Next
End Sub
'_______________________________________
But as far as pinpointing which one... I guess you could iterate each cell,
check when you are on a new row, count the number of cells there were in the
previous row, if the number is smaller than the columns count, there were
horizontally merged cells. You have to constantly check if there is a next
cell on the same row and whether you re on the last table row.
You could repeat for the vertically merged cell by going down the columns.
But what if a cell is merged horizontally and vertically?
AS you can see, this would require lots of code and hours of testing. Maybe
someone already has such code and is willing to share.
Or, there may be some clever trick / little know method/property I am
unaware of...
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org