How to unselect or deselect an object.

canes

New Member
Joined
Jun 16, 2004
Messages
7
Suppose a graphic obect on a worksheet is selected (A) by VBA or (II) by the user who, say, gets tossed by a Chart event. See code below.
Question is: How to cleanly deselect or unselect or selectnotwantnot the item (don't want selection handles no more) through VBA.
  • DO NOT want to select some arbitrary cell A1 or other address.
    DO NOT want to select some other off page or hidden object.
    DO NOT NOT want to issue Sendkeys {ESC}, False.
    DO NOT NOT not want to issue Sendkeys {ESC}, True.
Want code to produce equivalent of .Deselect or .Unselect if such a thing existed.

'Example (A) of code that does a select
Code:
Sub selchart() 
    ActiveSheet.ChartObjects(1).Select
End Sub
'Example (II) of code that traps a select
Code:
Private Sub myChartClass_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long)
    Select Case ElementID  
         Case xlChartTitle: MsgBox "Futz do not the chart title with."
    End Select
End Sub
 
Hi Brian

Don't know all the answer, but tried this and it inserted a new picture unselected:

Sub CallPicture()
On Error Resume Next
ActiveSheet.Pictures.Insert( _
"C:\My Documents\My Pictures\Waterfall.jpg").Visible
End Sub


also this seems to resize (or do other stuff) without selecting an existing picture:

Sub ResizePicture()
ActiveSheet.Shapes("Picture 17").Visible = True
ActiveSheet.Shapes("Picture 17").ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes("Picture 17").ScaleHeight 1.05, msoFalse, msoScaleFromBottomRight
End Sub

(Actually you don't need the first line if your picture is already visible)
regards
Derek
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Actually, this is better for inserting a picture:

"C:\My Documents\My Pictures\Waterfall.jpg").Visible = true


regards
Derek
 
Upvote 0
Sorry If I am posting too much that isn't relevant to your need to deselect, but I have been irritated by this before and am now quite chuffed to find this little bit works. This puts a picture on your sheet and names it PIX so you can then manipulate it without selecting it (here it moves it to A1 and resizes). You need to change the path to your own image.

Sub AddPicture()
Application.ScreenUpdating = False
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\DEREK\My Documents\My Pictures\Niagara.jpg").Name = "PIX"
ActiveSheet.Shapes("PIX").Visible = True
With ActiveSheet.Shapes("PIX")
.Left = Range("A1").Left
.Top = Range("A1").Top
.Height = 198.75
.Width = 264#
End With
End Sub

Hope someone finds this useful

regards
Derek
 
Upvote 0
I too am chuffed, whatever that means.
Thanks to everyone for their help.
I have found this very educational and useful.
 
Upvote 0
2022 and spreading the thanks:). I have no idea why that should work, but it does.:unsure:
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,968
Members
449,276
Latest member
surendra75

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