I'm trying to update the backcolor of all of the labels that I have on a worksheet. I'd like to indicate the color using the RGB values, but I'm stuck in two places. Here is the code that I have right now:
Sheet2.Shapes("Label 2").Fill.BackColor.RGB = RGB(220, 105, 0)
This code will run without error, but it seems to have no effect. My label starts out white (or maybe transparent) and never changes. Can anyone tell me what I need to do to make this work? I also added this but it did nothing:
shp.Fill.Solid
Next, I'd like to capture this RGB value in a variable so that I don't have to re-type of repeatedly. Essentially, I'm looking for something like this:
dim col as Color
col = RGB(220,105,0)
Sheet2.Shapes("Label 2").Fill.BackColor.RGB = col
I know that there is no variable type called Color, but I think you can see what I am trying to do.
Try setting the ForeColor instead:
Sheet2.Shapes("Label 2").Fill.ForeColor.RGB = RGB(220, 105, 0)
A good way to figure out what to do is to record a macro while you make the adjustment yourself. You can examine the generated code afterward and use it as a starting point.
Here is an example of a procedure that will add a rectangle to the activesheet, add some text to it, and then color it with your RGB values:
Public Sub AddRectangleWithText()
Dim textRectangle As Shape
Set textRectangle = ActiveSheet.Shapes & _
.AddShape(msoShapeRectangle, 10, 80, 250, 50)
' add your text
textRectangle.TextFrame.Characters.Text = "Your mother was a hamster."
' fill the shape with the rgb color of your choice
textRectangle.Fill.ForeColor.RGB = RGB(220, 105, 0)
End Sub
ForeColor actually controls the backcolor of comment/textbox(s) in Excel as follows;
Activecell.Comment.Shape.Fill.ForeColor.RGB = RGB(240, 255, 250)
'Mint Green
as the Comment/TextBox ForeColor is a foreground fill over the Applicatoin background color.
I needed to add
textRectangle.Fill.Visible = msoTrue
in Office 2016 for
textRectangle.Fill.ForeColor.RGB = RGB(220, 105, 0)
to have an effect.
Related
I have a TextBox just on the worksheet , I barely have tried everything to change Font and Back colours of it , but seems like can change only if TextBox is part of UserForm
Will be very appreciate for answers
To change the font color, let's say to red, try . . .
Worksheets("Sheet1").OLEObjects("TextBox1").Object.ForeColor = RGB(255, 0, 0)
To change the back color, let's say to blue, try . . .
Worksheets("Sheet1").OLEObjects("TextBox1").Object.BackColor = RGB(0, 112, 192)
Change the worksheet name and the RGB colors accordingly.
I need to automatically import a picture into excel and add a red circle. I am just starting to get the create a shape part but I cannot seem to figure out how to modify it. I have:
$WS = $workbook.worksheets.add()
$WS.select()
$ws.Activate()
$ws.Shapes.AddShape(9, 0, 0, 50, 50)
$circle = $ws.Shapes.AddShape(18, 50, 50, 50, 50)
#$Circle = $ws.Shapes[2]
write-host "fill: " $circle.fill
This adds an oval and a donut, but just outputs "system comobject" and I can't seem to access any of the methods that should be there (like fill/fillform.forecolor). What is the correct way to play with and modify the shape?
I can't test at the moment but try $circle.ShapeRange.Fill.ForeColor.RGB = RGB(255,0,0). Change the RGB values to your preference.
Im actually working on a VBA Excel Project. We have some requirements for the Color style of the whole sheet.
I designed a UserForm and it was possible to change all colors, except from the Drop Down Button of the ComboBox.
With these commands i can set the colors of Foreground, Background and Border:
Controls("ComboBox1").ForeColor = RGB(255, 255, 255)
Controls("ComboBox1").BackColor = RGB(0, 0, 0)
Controls("ComboBox1").BorderColor = RGB(160, 131, 101)
But i am not able to change the Drop Down button itself.. I searched a while but cant find anything..
Does anyone have an idea how to change this? Or is it set by Windows and not possible to change? Like this it looks a little ugly..
Thanks in Adance & best regards
I am trying to change the colour of a bullet point using VBA, but keep getting stuck. I want to make all the bullet points in a bullet list blue instead of black.
In Word you can not simply set the ParagraphFormat.Bullet.Font.Color (as in PowerPoint), but assign another style, e. g.
Selection.ParagraphFormat.Style = "List with red buttons"
Microsoft explains you alter its ParagraphFormat, using code similar to:
With Application.ActivePresentation.Slides(1).Shapes(2).TextFrame
With .TextRange.ParagraphFormat.Bullet
.Visible = True
.RelativeSize = 1.25
.Font.Color = RGB(255, 0, 255)
End With
End With
And, here's a color picker so you may get just the precise shade desired, translated into the RGB format (xxx,yyy,zzz) required.
I am trying to set the color of even lines and markers according to the color of odd lines and colors.
Let's say, my table looks like this (speed1, performance1, speed2, performance2,.....)
When I plot a line chart It just gives every line a different color. In my case I want to give every two columns (speed and performance) a single color. So, for that I try every time to take the color of a line and the color of its markers, and then assign these colors to the following line (color of odd columns to even columns).
This is my code:
Sub ChangeColors()
Dim cht As Chart
Dim ser As Series
Set cht = ActiveChart
For i = 1 To cht.SeriesCollection.Count
If (i Mod 2) = 0 Then
Set dst = cht.SeriesCollection(i)
Set src = cht.SeriesCollection(i - 1)
dst.Format.Line.Visible = msoFalse
dst.Format.Line.Visible = msoTrue
dst.Format.Line.ForeColor.RGB = src.Format.Line.ForeColor.RGB
dst.Format.Fill.ForeColor.RGB = src.Format.Fill.ForeColor.RGB
End If
Next i
End Sub
The problem is that at the end all the even lines become black. However, when I try to pick a RGB color (for instance, RGB(255, 0, 0)) an assign it to the even lines they all become red, so it works.
UPDATE:
When I use a MsgBox to print the value of src.Format.Line.ForeColor.RGB and src.Format.Fill.ForeColor.RGB I get 16777215 and 0 respectively for all lines. So I don't understand why these values and why they are the same for all lines ?
Does anyone know what is the problem with my code ?
Thank you !
Should this line:
dst.Format.Line.ForeColor.RGB = src.Format.Fill.ForeColor.RGB
instead be:
dst.Format.Line.ForeColor.RGB = src.Format.Line.ForeColor.RGB