Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

VBA Excel - How To Set Backcolor ?

Is it possible to view/set a backcolor for an excel cell using VBA ?


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
BackColor In Excel
I am trying to set the background colour of a cell depending on the value of that cell. Here is a basic version of what I am trying to do with a function in Visual Basic for Excel:

Function Test(a)
If a = 1 Then
Test = "Yess"
Object.BackColor = vbRed
End If
End Function

I don't know how to assign as an object or what goes before 'BackColor' ('Object' has been put in as an example).

Any help would be greatly appreciated.


Setting BackColor Of Excel's Active Cell Using VB !! Urgent !

Can anyone tell me how to set the BackColor of the Active Cell inside Worksheet in Excel ??

I am using this, but unfortunately it's not working....

objExcel.ActiveSheet.Cells(1,1).Font.BackColor = vbRed

Please help me as which property to use in order to set the BackColor of the Active Cell.

Thanks in Advance.

I have a .backcolor method in a rich text box change event, but nothing is happening. Such as if my forecolor is green and my backcolor is brown. then in the box, the text will be green with a white background. i ran it thru debug, and everything looks fine in the code.

Private Sub txtChat_Change()

Space = Chr(32)
TT = txtChat.Text
Call FindStart(FS)

If txtChat.Text <> Space And FS <> 0 Then
Call SetFonts

Call FindStart(FS)
With txtChat
.SelStart = FS - 1
.SelLength = 1
.SelColor = N
.BackColor = BN
.SelFontName = ftStyle
.SelBold = Bold
.SelItalic = Italic
.SelUnderline = Underline
.SelStrikeThru = Strikethrough
End With
TTRTF = txtChat.TextRTF
txtChat.TextRTF = TTRTF
TL = Len(TT)
txtChat.SelStart = TL
End If
End Sub

Sub SetFonts()
ftStyle = cboStyle.Text
ftSize = cboSize.Text

On Error GoTo setblack
N = ftColor
BN = vbWhite
Exit Sub

N = vbBlack
BN = vbWhite
Exit Sub
End Sub

How could I create a backcolor/forecolor property on a usercontrol?

When Creating a usercontrol and creating the backcolor property how can I make it be so a person can click on the arrow in the property window and colors will drop down. E.g. create form and look at the backcolor property in the property window a box apears with colors to select. How can I do the samething in my control?

Thanx in advance!

Backcolor In RTB??
The SetColor property of the RichTextBox sets the font color of the seleted text. I have been searching for a way to change the backcolor of the specific selection while I am making an IRC client where the user can change not only the text color but also the background color of his text.

Please - can anyone tell me how to do this?? API is welcome but no replacement controls if possible - I would like to keep all my code working.

Any help will be appreciated though!! Thanks in advance..1


I have this form which has hundreds of controls. ok not hundreds but many. now i have this requirement wherein the activecontrol's backcolor shud be highlighted; so the user knows where his cursor is in the 'hundreds' of controls.

Now i can write the code of changing colour on the gotfocus n lostfocus events. but for so many controls its not only a pain but to an extent bad programming. Can anyone suggest a better solution for this problem?

Me.BackColor=Me.BackColor + ?
Hello everybody....

I am trying to make a fading form. The backcolor property is an hex value, right? How can I add 1 to that hex value? Do you understand what I am trying to say? I want to increase the value little by little to fade the color. Can anyone help me with the Hex function?

how can i change the background color of a imageBox
how can i detect if a shape has been clicked, without looping
thru all the shape!!

I have set a specific background color for
my form. I need to get its R,G and B value.
VB assigns a specific number for eack color


A form displays a small image object without visible contours.
As I couldn’t find a way to fill picture back ground with truly transparent color, I selected the same color as form’s back ground, which is the system “menu color”.
But when program runs on a different system with other windows settings, form’s back color changes and a rectangle of different color becomes visible around the picture.
I tried selecting a fixed color to the form but palette tab doesn’t have the same color as system tab “menu color”.

Any idea?

Does anybody know how to change the color af the selected text in a RTFbox ,
not the backcolor of the whole textbox, just the selected text ?
Something like in Word you can use a marker.

Thank you

Backcolor Issue
I'v created a program using VB 6 and works fine on my Windows 2000 machine. However, when used on a computer with Windows XP some of the Backcolors appear different. Does anyone have any idea as to what may be causing this and how to fix it? Thanks in advance for any help.

MSFlexGrid Backcolor

A nice easy one for you. When I select a row in a FlexGrid I want it to change the backcolor of the cell toa different colour. I have played with .backColorSet to no avail. I was using cellBackColor which worked - I just couldn't get any previously selected rows to change back to white.

Can somebody help me please.


Toolbar Backcolor
Hi all

I just want to know that is there any way to get the back color of a tool bar?

I just want to change the back color of a toolbar control to the one of my form.

Just take a look at the picture below:

Menu Backcolor
Is there anyway you can make a menu backcolor not white? As in the Menu Editor? Most of my form is Button Face color, and then it looks crap with that white.


Backcolor Of Menu
all my forms have the same backcolor. one form has a menu.
the backcolor of the menubar and the menu itself always remain
gray. i can't even find how to get the properties of this menu.
is there a way to change the backcolor of both menubar and menu itself ?

Changing Backcolor
hello, im trying to change the backcolor of a shape, im trying this method below but it doesnt work for some reason. I get an error message; Type mismatch. This is the code im using.

Private Sub Timer1_Timer()
Shape1.BackColor = Text4.Text
Timer2.Enabled = True
Timer1.Enabled = False
End Sub

Private Sub Timer2_Timer()
Shape1.BackColor = Text5.Text
Shape2.BackColor = Text4.Text
Timer3.Enabled = True
Timer2.Enabled = False
End Sub

I entered a color code in the textboxes like this &H00400000& or &H00C00000&

.backcolor Change
Can someone give me an example on how to change the backcolor of a label when i go with my cursor over it. I dont want it to go from blue to white but from blue to some lighter blue and again from some lighter blue to almost with and then white, that you see the color change from blue to white in a flow. I dont know exactly how to do this all i know that i need a timer with it.

Changing BackColor
Is it possible to change the Background color of a menu and a status bar? I want my form to be a different color then grey, however it doesn't look right unless I can change the menu and status bar also.

Backcolor Codes?
Hi there.
How do I convert the backcolor of a userform in properties panel to RGB?
For instant, the selected color of the backcolor of the userform is "&H00C0FFC0&". What does it mean? How to converti it to RGB color code in xxx xxx xxx format?
Are there any conversion table for this?


Timer BackColor
Im making a timer to change background color every 500 m/s but it doesnt work. Please Help Thank You

Private Sub Timer1_Timer()
If Me.BackColor = &HFF& Then
Me.BackColor = 16777215
Label3.BackColor = 16777215
Label1.BackColor = 16777215
Label6.BackColor = 16777215
Label7.BackColor = 16777215
Label8.BackColor = 16777215
Label9.BackColor = 16777215
Label2.BackColor = 16777215
Label5.BackColor = 16777215
Label4.BackColor = 16777215
lblTax.BackColor = 16777215
lblDiscount.BackColor = 16777215
If Me.BackColor = 16777215 Then
Me.BackColor = &HFF0000
Label3.BackColor = &HFF0000
Label1.BackColor = &HFF0000
Label6.BackColor = &HFF0000
Label7.BackColor = &HFF0000
Label8.BackColor = &HFF0000
Label9.BackColor = &HFF0000
Label2.BackColor = &HFF0000
Label5.BackColor = &HFF0000
Label4.BackColor = &HFF0000
lblTax.BackColor = &HFF0000
lblDiscount.BackColor = &HFF0000
If Me.BackColor = &HFF0000 Then
Me.BackColor = &HFF&
Label3.BackColor = &HFF&
Label1.BackColor = &HFF&
Label6.BackColor = &HFF&
Label7.BackColor = &HFF&
Label8.BackColor = &HFF&
Label9.BackColor = &HFF&
Label2.BackColor = &HFF&
Label5.BackColor = &HFF&
Label4.BackColor = &HFF&
lblTax.BackColor = &HFF&
lblDiscount.BackColor = &HFF&

End If

End Sub

Row Backcolor MSHFlexGrid
Is it possible to change the backcolor of every even row?
and leace the color of the uneven rows..

Does anyone knows this? Thanx

Backcolor At Runtime
Is there a way to change the backcolor of all forms in my app at the same time? Without coding one form at a time?
Using something like
Allforms.backcolor = vbblack
Instead of
form1.backcolor = vbblack
form2.backcolor = vbblack, etc..

Also, how about all label backcolors? forecolors?


VB6 Custom BackColor
Is it possible to make the backColor a cutom color? I can not program in RGB, I also tried HTML color codes.

The color I want is:


VB names colors like this:

TextBox BackColor
On my form I have a Slider control and an array of textboxes. I am wanting to change the BackColor and ForColor of the textboxs when the index number matches the Slider.Value. My question is how do you change the backcolor and forcolor through code. Here is what I have so far, but it is not right. Could someone help with this please. Thanks

x = Slider1.Value
If Stxt(x).index = Slider1.Value Then
Stxt.BackColor = &H800000 'I get the error on this line
Stxt.Forcolor = &HFFFFFF
End If

MessageBox BackColor
Hi everyone...

Is it in anyway possible to change the MessageBox BackColor?
I know it is possible by creating custom messageboxes.
But i need to change the back color of the default MessageBox (msgbox).
Any useful comments will be greatly appreciated.

thanx n' regards

BackColor Question
Can anyone tell me why this code only colors row0 col5 on a MSFlexgrid?

With FG1
For i = 1 To 5
.Row = 0
.Col = i
.CellBackColor = &H80000001 'Dark Blue
.CellForeColor = &H8000000E 'White
Next i
End With

Where's My TreeView BackColor???
Oh no! I have a perfect little setup on my program where everything that needs filling has a nice subtle highlight, guiding the user along through the process of what needs to be filled before they can move along.

I'm almost finished, just have to do the same thing for the TreeView . . . and I find that there's no backcolor property for my TreeView!!! AHHHH!

There's got to be some way I can tweak this, right?

Text Backcolor
Is there a way to change the backcolor of just a certain piece of text, and not the entire text box?,

Print BackColor
Hey guys, when i do print my form, the backcolor just appear at half of the page.. what should i do ??

ListView Row Backcolor?
Hi All,

I'm trying to change the backcolor of a row in my listview...
But, this does not seem to work

Forecolor goes with ease...

Listview1.ListItems(1).ForeColor = vbRed
Listview1.ListItems(1).ListSubItems(1).ForeColor = vbRed

*sigh* now, a backcolor...

Can anyone help me? (No Subclassing plz)


Dbgrid Backcolor
I haven't seen a definite answer to this question yet so I figured I would ask. Is it possible to change the backcolor of specific rows on a dbgrid control? I would like to distinguish between open and closed records by changing the color of each row.

Random BackColor
How do I use a timer to randomly generate a form backcolor and change it at a set interval?

SSTab BackColor
How do I change the backcolor of a SSTAB control.

Thanks in Advance

Label Backcolor
Is it possible to make a label backcolor to invisible?

Plz help me!

.BackColor Pallet Tab
Dont mind this question.. but i am very new to VB and am looking for a simple question to be answered.

I am looking to change the BackColor properties (for all controls) and am wanting a different color thats not in the pallet tab. Is there a way i can bring up a color chart and select the color i wish to use.. I have not found a way to get the colors i want.

I am use to doing a lot of HTML and i just select the colors i want in my editor.. VB is limiting me to only a selected few or am i just not looking in the right place to select my BackColor.

Hope you can help. it would help me in making my apps look just like how i would want them too.

Thank You!

- Drew -

Somebody Plz Help Me With SStab Backcolor
I have a problem with setting the SSTAB backcolor. My application allows the user to select a background color and all the controls and forms in the project are set to that color.every thing works fine except for the sstab. All i need to do is either make the sstab transparent so that it shows form backcolor OR change sstab color to the form's backcolor ..
When the user changes the background color of the form, the sstab control and its tabs backcolor should be changed to the background color... i dont need to resize or do any other function on the sstab. Appreciate your help..
thanks again

Combo Box Backcolor
I need some help. I hava an access database. There is a form that displays all records from another form where information was entered. The combo box only has two options, OUT or RETURNED. I want to put in a condition that changes the backcolor when the value I specifiy is in the box onLoad.

Const RED = &H8080FF

example: If Combo1.Value = "OUT" then
Combo1.BackColor = RED
End If

This is very small, but I cannot get to work. I have tried .Value, .ListIndex, .Text but none of these work.
The conditions I try, either change the backcolor of all the records, or none at all.

A little help.

SSTab Backcolor
Is there any API to change SSTab's backcolor. (Whole tab portion)

Tabstrip Backcolor
Hi, I'm using the Tabstrip from Common Controls 5.0 with a manifest file in order to get the XP theme.

When I put a Frame on it, it has a different backcolor than the Tabstrip. The Tabstrip's backcolor is not solid, but gradient and it doesn't have a "BackColor" property either.

After searching for transparent Frames and Pictureboxes, the best solution seems to be to put a borderless Picturebox on the Tabstrip.

Then get the color from the first tab and give the Picturebox (and the controls inside) the same backcolor.

I use GetPixel to get the color from the first tab and it works fine with a Commandbutton, but when using it in the Form_Paint or Form_Initialize event in order to do it automatically, it's too fast and gets the color behind the form (i.e. desktop background).

Is there a solution for this?

vb Code:
Option Explicit Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As LongPrivate Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Sub Command1_Click()    Dim st As Long, pt As Long        st = GetDC(TabStrip1.hwnd)    pt = GetPixel(st, 2, 5)        Frame1.BackColor = pt    Picture1.BackColor = ptEnd Sub

DTPicker Backcolor
Is it possible to change the backcolor of a DTPicker?

I have changed the colour in the GotFocus and LostFocus events and the values are different when I print them to the Immediate window, but they still appear white.

Is there some property I have missed that I should be changing?

TabStrip BackColor
how can i change the tabstrip backcolor? help me pls?

TreeView Backcolor
Is there a way to change a Treeview's Background color using code, without changing the windows settings for it?

There's no property for it, so i figure there might be some kind of API call or something else to do it...

Also, is there a way to change the text color of it as well?

how to set the Tabstrip1.BackColor = VBWhite? help me pls?

Progress Bar BackColor
I'm using this to change the color of my progress bar
VB Code:
Public Declare Function SendMessage Lib _  "user32" Alias "SendMessageA" _  (ByVal hwnd As Long, _   ByVal wMsg As Long, _   ByVal wParam As Long, _   lParam As Any) As Long Public Const CCM_FIRST = &H2000Public Const CCM_SETBKCOLOR = (CCM_FIRST + 1)Public Const PBM_SETBKCOLOR = CCM_SETBKCOLORPublic Const WM_USER = &H400Public Const PBM_SETBARCOLOR = (WM_USER + 9) 'on formProgressBar1.hwnd, PBM_SETBKCOLOR, 0, ByVal RGB(0, 0, 126)
I want to use Green, but I don't know what the 126 would be replaced with in order to get it.


VB6 Button Backcolor
I am going nuts and I feel so stupid for not being able to figure this out!

I have four buttons, A B C and D, and when you click on A, I want the backcolor of the button to change. Then when you click on B, I want A to change back to grey, and for B's backcolor to change. Could anyone help me out with this?

Dtpicker Backcolor
I have a dtpicker inside my VB6 form.I want to set its back color to gray,but I don't have a backcolor property inside the properties window,I have only Calender backcolor.

How can I do it?

Copyright © 2005-08, All rights reserved