Error 438, Trouble with Formatting Shapes, Recorded Macro Not Working

FracinDean

Board Regular
Joined
Jul 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. Windows
I am attempting to use a macro to change the formatting of some shapes. I recorded some code with the macro recorder which works when I am recording it, but it doesn't work when I re-run it from the macro. Here is the code:

Code:
    ActiveChart.ChartArea.Select
    ActiveChart.Shapes.Range(Array("Freeform 1")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = -0.150000006
        .Transparency = 0
        .Solid
    End With

The error is "Run-time error '438': Object doesn't support this property or method."

The debugger is pointing to the statement "With Selection.ShapeRange.Fill"

This seems to be my last hurdle on this project. Thanks to past postings from this forum, I have learned tonight about how to delete the previous objects, use user-defined coordinates to draw the objects, and re-name the two objects so they are always #1 and #2.

Any assistance appreciated.
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
this selects a shape and colours it....

ActiveSheet.Shapes("Rectangle 1").Select
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
End Sub
 
Upvote 0
Solution
Thanks oldbrewer.

I get the same error again, this time on the statement:

Code:
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13

Any more suggestions?

In case it matters, I have Excel 10, version 14.0.7153.5000 (32-bit).
 
Upvote 0
I have the same code as my original now, and it is working. I don't know what is different this time, but the problem is solved for now. Thanks oldbrewer.
 
Upvote 0
This is a follow-up to document what I found to be the problem. The code is working reliably now. I had to add the identifier for the shape ("Freeform 1") to the third line of code below.

Code:
    ActiveChart.ChartArea.Select
    ActiveChart.Shapes.Range(Array("Freeform 1")).Select
    With Selection.ShapeRange("Freeform 1").Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorBackground1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = -0.150000006
        .Transparency = 0
        .Solid
    End With
 
Upvote 0

Forum statistics

Threads
1,216,076
Messages
6,128,670
Members
449,463
Latest member
Jojomen56

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