View Full Version : Solved: How to "Deselect" an AutoShape
Cyberdude
10-14-2005, 09:32 AM
At times I have to select an AutoShape (pseudobutton) to change its color or text message. After I finish, I want to deselect it. The "Deselect" method according to Help is for Chart objects. So in the past I've always just selected a handy cell to select. Any suggestions for the best way to deselect an AutoShape?
Zack Barresse
10-14-2005, 09:39 AM
AFAIK, you'll just need to reactivate your activecell...
Option Explicit
Sub Unselectshapes()
Dim rng As Range
Set rng = Selection
Stop
rng.Activate
End Sub
.. run the routine, when stopped, select your shape, then continue (F5); for testing purposes only.
Cyberdude
10-14-2005, 10:03 AM
Hi, Zack! I'm sorry, but I don't follow what you're trying to tell me. Consider the following macro:
Sub SetButtonMsgRed()
ActiveSheet.Shapes("AutoShape 1").Select
With Selection
.Characters.Text = "DON'T COPY"
.Characters.Font.Italic = True
.ShapeRange.Fill.ForeColor.SchemeColor = AutoShapeRed
End With
Iwant a deselect stmt here before exiting
End Sub
In the past I've just used somethng like
Range("A1").select
or the like because there are some cases where a macro like this one might be called by another button rather than another macro.
This brings up another question .... is it ever possible to be in a state where nothing is selected??
Zack Barresse
10-14-2005, 10:12 AM
Sub SetButtonMsgRed()
Dim r as range
set r = selection
ActiveSheet.Shapes("AutoShape 1").Select
With Selection
.Characters.Text = "DON'T COPY"
.Characters.Font.Italic = True
.ShapeRange.Fill.ForeColor.SchemeColor = AutoShapeRed
End With
r.activate
End Sub
This brings up another question .... is it ever possible to be in a state where nothing is selected??
Don't believe so. I think something has to be the activewindow/selection.
Cyberdude
10-14-2005, 10:25 AM
Thanx, Zack.
malik641
10-14-2005, 12:19 PM
Correct me if I'm wrong, but I don't think you have to actually Select the shape to modify anything.
Check it out:
Sub SetButtonMsgRed()
With ActiveSheet.Shapes("AutoShape 1")
.TextFrame.Characters.Text = "DON'T COPY"
.TextFrame.Characters.Font.Italic = True
.Fill.ForeColor.SchemeColor = 2
End With
End Sub
And BTW does ANYBODY know where I can find Excel's Shape properties? Just figuring this out took me too long because I'm not familiar with the properties of Excel's shapes...but I knew that this could be done, just not obviously - like recording a macro and noting the recorded code.
AND VBA doesn't have any autolist members for shapes http://vbaexpress.com/forum/images/smilies/102.gif What gives?
EDIT: Just found this on the web, VERY useful for this subject:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaxl11/html/xlobjShape1_HV05204994.asp
Zack Barresse
10-14-2005, 12:39 PM
Yes, it's all about the Shapes Collection, which is very, very wide and encompassing.
Cyberdude
10-14-2005, 01:57 PM
Great idea, malik641! I had to make some changes to make it work, but it does indeed work and makes it unnecessary to have a deselect. Just what I was looking for. Thanx a million. http://vbaexpress.com/forum/images/smilies/friendship.gif
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.