0

I have a table in Word. What I would like to do is to sum the numbers from the rows that were highlighted (in only one column). I found on the internet the way to sum the content of the cells if they have specific background color, and then using this thread I changed the function so that it checks for the highlight color, not background. That's what I created:

Function ColorIndex(Rng As Range)
  ColorIndex = Rng.Interior.ColorIndex
End Function

But, then when I wanted to check if it works in Excel, I realised that in Excel there is no 'higlight the text' option at all. It made me realise that probably the function would not be doing what I want anyway, I checked and as I expected, it would return the color of the cell background. Therefore, I wanted to see if the function will work in Word, but apparently you can only use some pre-programmed functions in Word, and I cannot choose the function I created in VBA using Insert -> Module. That's why I have two questions:

1) Is it possible to use a function created by VBA in Word table and if yes, how to do it?
2) Is there a way to have a function that would check whether the text is highlighted?

Community
  • 1
  • 1
joanxm
  • 1

1 Answers1

0
  1. You can use VBA code in Word documents and tables BUT the VBA that works with the tables/cells is NOT the same as the Excel code. Different application, different object model.

  2. Certainly. The Range.HighlightColorIndex returns the highlight color (WdColorIndex, as an integer) applied to the Range. No highlight is wdNoHighlight, integer value = 0.

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43