Need code to make selected shape transparent

djl0525

Well-known Member
Joined
Dec 11, 2004
Messages
1,240
I need two (separate) macros.

1. Change fill color of select shape to black.
2. Change fill color of select shape to transparent.

I tried recording them, but the steps are not captured.

Note: The shape will always be selected before the code is run.

Thanks for your help.
--DJ
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this

Code:
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 8
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

remove the fill again ( making the fill none therefore transparent ? )

Code:
Selection.ShapeRange.Fill.Visible = msoFalse
 
Upvote 0
Thanks! This is just what I needed.

I added keyboard shortcuts to them, but only the shortcut for black works. Do you see any reason the shortcut for the transparent code wouldn't work? They're in different modules.

--DJ

Code:
Sub ShapeFillBlack()
'04/18/09 - Written by MrExcel's S8utt
'Source: http://www.mrexcel.com/forum/showthread.php?t=384877
'This code changes a shape's fill color to black

' Keyboard Shortcut: Ctrl+e

    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 8
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
End Sub
Code:
Sub ShapeFillNone()
'04/18/09 - Written by MrExcel's S8utt
'Source: http://www.mrexcel.com/forum/showthread.php?t=384877
'This code changes a shape's fill color to transparent

' Keyboard Shortcut: Ctrl+t

Selection.ShapeRange.Fill.Visible = msoFalse
End Sub
 
Upvote 0
Note sure here is all the code for both operations.

Fill Colour
Code:
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 8
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

unfill
Code:
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.Transparency = 0#
    Selection.ShapeRange.Line.Weight = 0.75
    Selection.ShapeRange.Line.DashStyle = msoLineSolid
    Selection.ShapeRange.Line.Style = msoLineSingle
    Selection.ShapeRange.Line.Transparency = 0#
    Selection.ShapeRange.Line.Visible = msoTrue
    Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
    Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

i eliminated the line comments and just kept the lines that had fill in them

Code:
    Selection.ShapeRange.Fill.Visible = msoTrue
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.ForeColor.SchemeColor = 8
    Selection.ShapeRange.Fill.Transparency = 0#
Code:
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.Fill.Solid
    Selection.ShapeRange.Fill.Transparency = 0#

obviously the trasparency and solid lines are the same.
What I would do is run the macro to make it transparent and then go into the format shape box and see what still needs to be set to make it no fill, maybe give us an idea where to start.

The previous macro worked for me fine on excel 2003
 
Upvote 0

Forum statistics

Threads
1,221,841
Messages
6,162,314
Members
451,759
Latest member
damav78

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