Consulting

Results 1 to 6 of 6

Thread: Deselect Object

  1. #1
    VBAX Regular
    Joined
    Aug 2009
    Posts
    8
    Location

    Deselect Object

    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

  2. #2
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    if all you wanted to do is "move" the focus away, can you not do this
    [vba]
    range("A1").select
    [/vba]

  3. #3
    VBAX Regular
    Joined
    Aug 2009
    Posts
    8
    Location
    Quote Originally Posted by JKwan
    if all you wanted to do is "move" the focus away, can you not do this
    [vba]
    range("A1").select
    [/vba]
    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

  4. #4
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    sjm, set a flag ieB range.select =1;
    if a1.select == true
    {
    do something
    }
    else {
    do something different
    }

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by SJM
    [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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    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.
    [VBA]Sub SelectTopLeft()
    ActiveSheet.OLEObjects("oPDF").Verb xlPrimary
    ActiveSheet.OLEObjects("oPDF").TopLeftCell.Select
    End Sub
    [/VBA]

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •