-1

Sorry for maybe unintelligible title but i cant find out how to write this better.

I've got Excel VBA code that transforms the sheet from Excel for a version to print in a Word. The problem is that when a specific cell in a row in Excel is red colour or is equal to "ENG_AT" text I need to color content of cell which will be printed.

Here you got the original working code sample.

ElseIf Not IsEmpty(calArray(i, 3)) And IsEmpty(calArray(i, 2))  Then
    'item
    styleName = "N1"
    headerText=calArray(i, 12)
    .Rows(t).Borders(-3).LineStyle = 7

calArray(i,12) is cell that is going to print.

And this is part where I tried to add my statement

ElseIf Not IsEmpty(calArray(i, 3)) And IsEmpty(calArray(i, 2)) And calArray(i, 16) = "ENG_AT" Then
    'item
    styleName = "N1"
    Dim Text2 As String
    Text2 = UCase(calArray(i, 12)
    Text2.Interior.Color = RGB(0, 0, 250)

    headerText = Text2
    '.Font.Underline = True
    .Rows(t).Borders(-3).LineStyle = 7

All I've done is only to uppercase a letters, rest is not working. I would be really happy if someone could explain to me how can I change color of destination cell in Word table or just underline this text.

Thank you in advance for help.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 1
    ¿Are you sure this is the right code? because `Text2 = UCase(calArray(i, 12)` is missing a parenthesis, and `Text2.Interior.Color = RGB(0, 0, 250)` makes no sense, because `Text2` is declared as a variable, not as an object, so it cannot have any properties – Foxfire And Burns And Burns Jul 30 '18 at 09:08
  • The first code sample is correct, the second one is my try, Text2 = UCase(calArray(i, 12) is working but line with RGB part not, have you got any idea how can i make this text red or underline, because i dont know even how to try in other way. – Galinowsky Jul 30 '18 at 09:16
  • In order to give you a good answer you need to show us the code you use to write that text into Word. I assume it has something to to with .Rows(t)... but as you don't show the `With` that presumably precedes this it's impossible for us to know. Please use the [edit] link below your question to provide FULL information. – Cindy Meister Jul 30 '18 at 14:35

1 Answers1

0

Not knowing the specific variables you are using in your solution, the following is just a generic way to assign a color to the text in a Word table cell.

    ActiveDocument.Tables(1).rows(1).Cells(3).Range.Font.ColorIndex = wdRed
Rich Michaels
  • 1,663
  • 2
  • 12
  • 18