How do I change the background color of a cell in Word use VSTO or COM

La La 1 Reputation point
2022-08-10T06:21:43.12+00:00

i can add table and get cell , but can't change the cell background color

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points
    2022-11-09T11:48:07.587+00:00

    Did you try record this change using Word?

    For me is working fine:

      Selection.Shading.Texture = wdTextureNone  
      Selection.Shading.ForegroundPatternColor = wdColorAutomatic  
      Selection.Shading.BackgroundPatternColor = -721354855  
    

    Ater that you declate Table, cells range and replace selection command for cells.range like this

    Dim t As Table: Set t = ActiveDocument.Tables(1)  
    t.Range.Cells(2).Shading.BackgroundPatternColor = wdColorBlue  
    

    In vb.net delete set commend and so on...
    Regards

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.