VBA - Color/Colour Shape Fill and Line

i_excel

Board Regular
Joined
Jun 4, 2015
Messages
113
Hey

I've got an oval that I would like to colour. I want to change the colour of its fill and border.

I am currently using this code without success:

Code:
 With ActiveSheet.Shapes("Oval 1")

    .Fill.ForeColor.RGB = RGB(217, 0, 217)
    .Line.BackColor.RGB = RGB(198, 217, 241)
    .TextFrame.Characters.Font.Color = RGB(255, 255, 255)
    .Select

I was hoping that someone could explain to me why that was.. The code selects the oval as desired, which makes me think that the preceding colouring code is not buggy but that something else is standing in the way..

Any help would be much appreciated.

Kind regards
i_excel

PS I am not sure what .textframe does yet, but it is not the culprit preventing colouring..
 
Last edited:

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You have to select the shape first....before you colour it !!!
Code:
Sub MM1()
With ActiveSheet.Shapes("Oval 1")
    .Select
    .Fill.ForeColor.RGB = RGB(217, 0, 217)
    .Line.BackColor.RGB = RGB(198, 217, 241)
    .TextFrame.Characters.Font.Color = RGB(255, 255, 255)
End With
Range("A1").Select
End Sub
 
Upvote 0
You have to select the shape first....before you colour it !!!
Hi Michael,
I don't think you have to select the shape to change its format. The OP's code works fine for me (after adding an End With), but I think the .Line.Backcolor ... should be .Line.ForeColor... to add a visible border.
Code:
 With ActiveSheet.Shapes("Oval 1")
    .Fill.ForeColor.RGB = RGB(217, 0, 217)
    .Line.ForeColor.RGB = RGB(198, 217, 241)
    .TextFrame.Characters.Font.Color = RGB(255, 255, 255)
    .Select
    End With
 
Upvote 0
Hi (again) Michael M and JoeMo

Thank you both for your help. I cannot explain why, but the initial code (edited as you suggested JoeMo) is now working. It started working after I manually changed the shape fill to some other colour first.. I don't understand but at least it works now..

Regards

i_excel

PS My bad for missing the "end with" from my original post. It wasn't missing from my sub and so isn't a suspect.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,481
Messages
6,160,083
Members
451,616
Latest member
swgrinder

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top