Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Cell Object/Collection

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 18 Nov 2007 15:35 GMT
If I create an table and add some cell specific shading then I can run this
code to change the shading:

Sub Test()
Dim oCell As Word.Cell
Dim oTbl As Word.Table
For Each oTbl In ActiveDocument.Tables
 For Each oCell In oTbl.Range.Cells
   If oCell.Shading.BackgroundPatternColor = RGB(229, 170, 91) Then
     oCell.Shading.BackgroundPatternColor = RGB(93, 143, 86)
   End If
 Next
Next
End Sub

This works for a uniform table and it works on tables where cells are merge
horizontally.  However, if I merge cells vertically then this code misses
the vertical merged cells.

If a vertically merged cell isn't a cell or part of a table cell collection
then what is it?

Thanks.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Russ - 18 Nov 2007 20:01 GMT
Greg,
If I comment out your "If" test, it shades every cell in my 'virgin' test
table with three middle cells merged vertically?
And msgbox activedocument.tables(1).range.cells.count returns an accurate
cell count after merging.
Are you merging cells after a shading is applied and that is skewing the
background shading "If" test? Like the font property undefined code 999...?

Sub Test()
Dim oCell As Word.Cell
Dim oTbl As Word.Table
For Each oTbl In ActiveDocument.Tables
 For Each oCell In oTbl.Range.Cells
  ' If oCell.Shading.BackgroundPatternColor = RGB(229, 170, 91) Then
     oCell.Shading.BackgroundPatternColor = RGB(93, 143, 86)
   'End If
 Next
Next
End Sub

> If I create an table and add some cell specific shading then I can run this
> code to change the shading:
[quoted text clipped - 19 lines]
>
> Thanks.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Russ - 18 Nov 2007 20:31 GMT
Greg,
Experimenting further, I was able to duplicate the problem when rows
contained both vertical and horizontal merged cells. I put a message box
line and a oCell.Select line in the loop and I always saw the msgbox text
but some cells didn't become selected or shaded.

I tried to use range and that seemed to work.
For example:
oCell.Range.Shading.BackgroundPatternColor = RGB(93, 143, 86)

So it appears that the range object works better than the 'default'
selection object in this situation.

> Greg,
> If I comment out your "If" test, it shades every cell in my 'virgin' test
[quoted text clipped - 39 lines]
>>
>> Thanks.

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

Greg Maxey - 18 Nov 2007 23:39 GMT
Russ,

Thanks for working that out.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg,
> Experimenting further, I was able to duplicate the problem when rows
[quoted text clipped - 53 lines]
>>>
>>> Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.