Can't get border on shape to deselect


Jeff Wright


I have the following macro which adds a line to an existing oval shape. The
macro works fine, except the shape is still selected when the macro
finishes. I've tried inserting "ActiveSheet.Shapes("Oval 1").Deselect" at
the end of the code, but I get a "runtime error 438." Is there a way I can
get the macro to leave the shape in unselected mode when it finishes?



Sub addborder1()
ActiveSheet.Shapes("Oval 1").Select
Selection.ShapeRange.Line.Weight = 8#
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 = 8
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
End Sub

Dave Peterson

You should be able to select a cell to get off the Oval--
at the bottom of your code: ActiveCell.Activate

But maybe better is to not select the oval to manipulate it:

Option Explicit
Sub addborder1A()
With ActiveSheet.Shapes("Oval 1").Line
.Weight = 8#
.DashStyle = msoLineSolid
.Style = msoLineSingle
.Transparency = 0#
.Visible = msoTrue
.ForeColor.SchemeColor = 8
.BackColor.RGB = RGB(255, 255, 255)
End With
End Sub

Jeff Wright

Dave, thanks! This now works the way I want it to. I keep forgetting (as I
continue to learn VBA) that you don't necessarily have to select an object
in order to work with it.

Thanks again,


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question