Results 1 to 14 of 14

Thread: loop through tables in word and change color of cells

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,273
    Location
    Try:
    Sub Colora()
    Application.ScreenUpdating = False
    Dim MyTable As Table, MyCell As Cell, BkGrnd As Long
    For Each MyTable In ActiveDocument.Tables
      For Each MyCell In MyTable.Range.Cells
        Select Case Split(MyCell.Range.Text, vbCr)(0)
          Case "I":  BkGrnd = wdColorBlue
          Case "V":  BkGrnd = wdColorRed
          Case Else: BkGrnd = wdColorAutomatic
        End Select
        MyCell.Shading.BackgroundPatternColor = BkGrnd
      Next MyCell
    Next MyTable
    Set MyCell = Nothing: Set MyTable = Nothing
    Application.ScreenUpdating = True
    End Sub
    Last edited by macropod; 01-24-2021 at 02:12 PM.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •