PDA

View Full Version : Deselect Object



SJM
11-29-2010, 12:45 PM
I have a pdf file embedded in Excel. I need to unselect it after user double clicks on the object otherwise I get an error executing the rest of the code. So my question is how I deselect an object. Apparently ActiveSheet.Shapes.Range("Test").Select works but ActiveSheet.Shapes.Range("Test").Deselect does not work

Thanks in advance
SJM

JKwan
11-29-2010, 01:12 PM
if all you wanted to do is "move" the focus away, can you not do this

range("A1").select

SJM
11-29-2010, 04:05 PM
if all you wanted to do is "move" the focus away, can you not do this

range("A1").select


Yes, I could do that. However, I was hoping for more elegant solution. I was hoping to check if the object is selected and then deselect it in the worksheet change event to avoid error. I guess I will have to use target.select as the first line in the worksheet change event.

Thank you for the suggestion.
SJM

Trevor
11-29-2010, 10:07 PM
sjm, set a flag ieB range.select =1;
if a1.select == true
{
do something
}
else {
do something different
}

xld
11-30-2010, 01:15 AM
[COLOR=black]Yes, I could do that. However, I was hoping for more elegant solution. I was hoping to check if the object is selected and then deselect it in the worksheet change event to avoid error.

As you have found there is no DeSelect method, the only way is to select something else.

Kenneth Hobs
11-30-2010, 07:27 AM
I am not sure why your worksheet change or selectionchange event would happen when you doubleclick the object as mine does not.

If you want to keep the user near their selection, you can use the topleftcell. I renamed "Object 2" to "oPDF" in this example. I assigned this macro. It fires on a single click but a double or two clicks will activate the PDF.
Sub SelectTopLeft()
ActiveSheet.OLEObjects("oPDF").Verb xlPrimary
ActiveSheet.OLEObjects("oPDF").TopLeftCell.Select
End Sub


You may want to use Application.EnableEvents and set it to False if you don't want a selection event to fire when you Select in the code. Be sure to set it back to True at the end.