Why does the first example of code work but second does not? Excel says .ShapeRange.Fill causes Error 438 -- Trying to learn about shapes.

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
855
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
'This works   
    ActiveSheet.Shapes.Range(Array("TestShape1")).Select
    With Selection.ShapeRange.Fill
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0.6000000238
        .Transparency = 0
        .Solid
    End With

'   This chokes    
    With ActiveSheet.Shapes.Range(Array("TestShape1"))
        With .ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorAccent1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0.6000000238
            .Transparency = 0
            .Solid
        End With
    End With
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
You are missing the word Selection

Rich (BB code):
'   This chokes
    With ActiveSheet.Shapes.Range(Array("TestShape1"))
        With Selection.ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorAccent1
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0.6000000238
            .Transparency = 0
            .Solid
        End With
    End With
 
Upvote 0
Thanks DanteAmor! I guess that I'm just thick-headed. I think that I made some progess.

Dim oShape As Shape

Set oShape = ActiveSheet.Shapes("TestShape1")

With oShape
With .Fill
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorAccent1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0.6000000238
.Transparency = 0
.Solid
End With
End With
 
Upvote 0
The With statement allows you to perform a series of statements on a specified object without requalifying the name of the object.

Then:

VBA Code:
Sub test2()
  Dim oShape As Shape
 
  Set oShape = ActiveSheet.Shapes("TestShape1")
 
  With oShape.Fill
    .Visible = msoTrue
    .ForeColor.ObjectThemeColor = msoThemeColorAccent1
    .ForeColor.TintAndShade = 0
    .ForeColor.Brightness = 0.6000000238
    .Transparency = 0
    .Solid
  End With
End Sub

Or simply:
VBA Code:
Sub test3()
  With ActiveSheet.Shapes("TestShape1").Fill
    .Visible = msoTrue
    .ForeColor.ObjectThemeColor = msoThemeColorAccent1
    .ForeColor.TintAndShade = 0
    .ForeColor.Brightness = 0.6000000238
    .Transparency = 0
    .Solid
  End With
End Sub

Another way to apply it:

VBA Code:
Sub test4()
  With ActiveSheet.Shapes("TestShape1").Fill
    .Visible = msoTrue
    
    With .ForeColor
      .ObjectThemeColor = msoThemeColorAccent1
      .TintAndShade = 0
      .Brightness = 0.6000000238
    End With
    
    .Transparency = 0
    .Solid
  End With
End Sub


:cool:
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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