Using VBA to change colour of table cells

  • Thread starter Roderick O'Regan
  • Start date
R

Roderick O'Regan

I've got a list of 13 different colour values which would allow a user to
select one from a commandbar menu item. This might say e.g. Green, Ochre,
Red and so on. In turn it would apply the appropriate RGB value to the
cells.

Something like in the following:
With Selection.Cells.Shading
.BackgroundPatternColor = RGB(150, 210, 56)
End With

How could I write a procedure, please, that would still keep the same menu
selections but change the RGB value in the few lines above and not have to
write 13 versions of each setting?

This should be able to work in Word 97 right up to 2002.

Regards

Roderick O'Regan
 
J

Jezebel

Attach the colour values -- RGB() returns a long -- to the menu's tag
property, then use that:

..BackgroundPatternColor = MyMenu.Tag
 
R

Roderick O'Regan

Thanks for the tip.

I've never used the .Tag property before so this will be a good place to get
to know what it can do for me.

Roderick
 
R

Roderick O'Regan

I've tried doing that after your suggestion but I've discovered that the Tag
property only returns strings. When I apply that to the
..backgroundPatternColour I get a type mismatch. I suppose because one is a
string and the other a Long value.

Any alternative suggestions, please?

Roderick O'Regan
 
J

Jezebel

clng(ctrl.tag)



Roderick O'Regan said:
I've tried doing that after your suggestion but I've discovered that the Tag
property only returns strings. When I apply that to the
.backgroundPatternColour I get a type mismatch. I suppose because one is a
string and the other a Long value.

Any alternative suggestions, please?

Roderick O'Regan
user have
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top