Hi,
I'm Sneha and I'd be happy to help you out with your question. Sorry for the inconvenience caused.
It looks like there is an issue with the ObjectThemeColor property of the ForeColor object. The error message indicates that the specified value is out of range, which means that the value you are trying to set for the ObjectThemeColor property is not valid.
There are a few possible reasons why this error might be occurring:
- The value you are trying to set for the ObjectThemeColor property is not one of the predefined theme colors. The ObjectThemeColor property can only be set to one of the predefined theme colors, which are represented by constants in the msoThemeColor enumeration. Make sure you are using a valid constant from this enumeration.
- The theme you are using does not have an accent color with the index you are specifying. The msoThemeColorAccent5 constant corresponds to the fifth accent color in the current theme. If the current theme does not have an accent color with this index, you will get an error.
- There is an issue with the Shape object itself. It's possible that the Shape object you are trying to modify does not exist, or there is some other issue with it that is causing the error.
To troubleshoot this issue, you can try the following:
- Make sure you are using a valid constant from the msoThemeColor enumeration for the ObjectThemeColor property.
- Check the current theme to make sure it has an accent color with the index you are specifying. You can do this by going to the Page Layout tab in the ribbon and clicking on the "Colors" button in the "Themes" group. This will open the "Colors" dialog, where you can see all the accent colors in the current theme.
- Make sure the Shape object you are trying to modify exists and is in a valid state. You can check this by adding some debugging code to your macro to print out the name and type of the Shape object. You can also try selecting the Shape object manually to see if there are any issues with it.
Here is the corrected code that should work without any errors:
Sub Macro3()
Dim shape As Shape
Set shape = ActiveSheet.Shapes("Rounded Rectangle 2")
With shape. Fill
. Visible = msoTrue
. ForeColor.ObjectThemeColor = msoThemeColorAccent5
. ForeColor.TintAndShade = 0
. ForeColor.Brightness = 0.4
. Transparency = 0
. Solid
End With
End Sub
In this code, I have declared a variable shape of type Shape, and used the Set statement to assign the Shape object with the name "Rounded Rectangle 2" to this variable. I have then modified the properties of the Fill object of the shape object, rather than the Selection object.
This should fix the error you were seeing, and allow you to change the fill color of the Shape object as intended.
If you have any other questions or need assistance with anything, please don't hesitate to let me know. I'm here to help to the best of my ability.
Give back to the Community. Help the next person who has this issue by indicating if this reply solved your problem. Click Yes or No below.
Best Regards,
Sneha