PDA

View Full Version : [SOLVED:] RGB Array - Split to Dimension 2,1



dj44
02-21-2017, 06:16 PM
Hi folks,

Got a tricky one

How do I make an RGB point to a dimension array




Dim oPara As Paragraph
Dim var(2, 1)
Dim lngIndex As Long
Dim oRng As Range
var(0, 0) = "Green"
var(0, 1) = RGB(0, 255, 0)

some more colors later



Should I make a new variable and do this

var(lngIndex, 1) = RGB((0), (1), (2))

and then stuck

gmaxey
02-21-2017, 07:03 PM
It appears to me that you already have:


Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oPara As Paragraph
Dim var(2, 1)
Dim lngIndex As Long
Dim oRng As Range
var(0, 0) = "Green"
var(0, 1) = RGB(0, 255, 0)
var(1, 0) = "Red"
var(1, 1) = RGB(255, 0, 0)
var(2, 0) = "Bluu"
var(2, 1) = RGB(0, 0, 255)
Set oRng = ActiveDocument.Paragraphs(1).Range
oRng.Shading.BackgroundPatternColor = var(2, 1)
lbl_Exit:
Exit Sub
End Sub

dj44
02-21-2017, 07:51 PM
Thank's Greg,

I had to really cut back on the dogs dinner i made of the code - to only this snippet,
I know id get told off for being sloppy as per my postings :grinhalo:

everything is to do with excel arrays nothing on word, i was trying to make it simple with this idea but it got complicated very fast

its all solved now - thank you

it worked a charm

Yes I was trying to highlight some sentences with colors as i cant see them with the bad fonts thats another story

Have a good evening

Paul_Hossler
02-22-2017, 11:49 AM
Don't forget that you can use the built-in color constants directly



ActiveDocument.Paragraphs(1).Range.Shading.BackgroundPatternColor = vbRed



18442

dj44
02-22-2017, 05:18 PM
Thanks Paul,
when I have a chance I will also investigate how to use the hex color as well, sometimes i get a hex color and i cant make it in rgb.
it gives a strange color

var(0, 0) = "Green"
var(0, 1) = &HFF00

Gave black - I may need to convert it

Paul_Hossler
02-22-2017, 06:20 PM
Try

var(0, 1) = &h00ff00&

for Green, but it's much easier to just use vbGreen