Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Change MSword table cell background programatically
Message
From
07/07/2009 17:18:38
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01410445
Message ID:
01410746
Views:
34
Thanks Borislav

I only had a small issue with the following line
oWord.Selection.Shading.BackgroundPatternColor = -553582746
I fixed by finding the right number

Thanks again

>>Can I change the background of a table's cell background programmatically in MS Word document.
>>
>>I am building a matrix that need to have different color based on query result.
>>
>>Thanks
>
>Sure, try this:
>
>
>#define wdTextureNone    0
>#define wdColorAutomatic -16777216
>
>LOCAL oWord AS Word.Application
>oWord = CREATEOBJECT("Word.Application")
>oWord.Documents.Add()
>oWord.Visible = .t.
>oWord.ActiveDocument.Tables.Add(oWord.Selection.Range,3,3) && Add 3x3 grid 
>WITH oWord.ActiveDocument.Tables(1)
>     .Style = "Table Grid"
>     .ApplyStyleHeadingRows = .t.
>     .ApplyStyleLastRow     = .f.
>     .ApplyStyleFirstColumn = .t.
>     .ApplyStyleLastColumn  = .f.
>     .ApplyStyleRowBands    = .t.
>     .ApplyStyleColumnBands = .f.
>ENDWITH
>
>
>oWord.ActiveDocument.Tables(1).Cell(1,2).Select()  && Select cell we want to change
>oWord.Selection.Shading.Texture                = wdTextureNone
>oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
>oWord.Selection.Shading.BackgroundPatternColor = -553582746
>
>oWord.ActiveDocument.Tables(1).Cell(2,1).Select()
>oWord.Selection.Shading.Texture                = wdTextureNone
>oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
>oWord.Selection.Shading.BackgroundPatternColor = -553582746
>
>oWord.ActiveDocument.Tables(1).Cell(2,3).Select()
>oWord.Selection.Shading.Texture                = wdTextureNone
>oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
>oWord.Selection.Shading.BackgroundPatternColor = -553582746
>
>oWord.ActiveDocument.Tables(1).Cell(3,2).Select()
>oWord.Selection.Shading.Texture                = wdTextureNone
>oWord.Selection.Shading.ForegroundPatternColor = wdColorAutomatic
>oWord.Selection.Shading.BackgroundPatternColor = -553582746
>
Previous
Reply
Map
View

Click here to load this message in the networking platform