+ Reply to Thread
Results 1 to 7 of 7

How to Act on a Mouse Click

  1. #1
    Registered User
    Join Date
    10-01-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    How to Act on a Mouse Click

    I want to write code for picking a default folder where the data file to be imported is stored. This default path is stored in, say, Cell B1. Another similar path for another data file is stored in, say, cell B3. I have written the code for displaying a browse window for picking up the folder as under -

    Please Login or Register  to view this content.
    Now the help I need is to suggest a code so that when a user mouse clicks on cell B1, the above code is executed and the returned value is stored in Cell B1 and when he clicks on cell B3, the above code is executed and the returned value be stored in cell B3.

    It will still be better if the mouse click and an 'Enter' key both can be identified to execute the above code.
    Learning is enjoyable. Enjoying learning.

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to Act on a Mouse Click

    Try this

    With the Sheet you want to execute your code.

    Right-Click the Sheet Tab > Click View Code
    Paste all of this in the resultant pane
    Please Login or Register  to view this content.
    Delete your original code. (It's included in the above code.)

    Close the VBa editor and save the workbook.

    Click in cell B1 or B3 to run your code.

    Is that what you are after?
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    10-01-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: How to Act on a Mouse Click

    Quote Originally Posted by Marcol View Post
    Try this

    Is that what you are after?
    Thanks Marcol. This worked. Only a few further issues -

    1. Since this traps a change event only, it does not take care of the following situation :
    A user clicks on the cell and a browse windows pops up. He selects a folder, clicks 'Open/OK' and the returned path is stored in the cell. Suddenly he notices that he picked a wrong folder and clicks the mouse again (he is still in the same cell) to have the browse window again, but this time the window won't open. He will have to go to another cell and then come back to this cell to get the browse/pickup window again.

    2. In my worksheet the cells B1,C1 & D1 were merged cells for visual effect. I had to split the merged cells for the function to work.

    Any solution to overcome these issues?

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to Act on a Mouse Click

    1/. Try this code instead
    Change the offset if you have to, but best if it is an adjacent cell
    Please Login or Register  to view this content.

    2/. Avoid merging cells, merged cells cause more problems than they are worth.
    In this case you could possibly use C1 centered, instead of B1, then format B1,C1,D1 to get the desired visual effect.
    Last edited by Marcol; 10-24-2010 at 07:41 AM.

  5. #5
    Registered User
    Join Date
    10-01-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: How to Act on a Mouse Click

    Quote Originally Posted by Marcol View Post
    1/. Try this code instead
    Change the offset if you have to, but best if it is an adjacent cell
    Thanks Marcol, It's a good workaround but it fails in case you exit from the folder selection window without selecting a folder i.e. if you select 'cancel'.

    Any further suggestion?

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to Act on a Mouse Click

    Hmmm....seems to work okay for me.

    This modification will clear the cell if there is no folder selected, (might be handy if you need to delete the reference)
    Please Login or Register  to view this content.

    Have you made any other changes?

  7. #7
    Registered User
    Join Date
    10-01-2010
    Location
    Mumbai, India
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: How to Act on a Mouse Click

    Quote Originally Posted by Marcol View Post
    Hmmm....seems to work okay for me.

    This modification will clear the cell if there is no folder selected, (might be handy if you need to delete the reference)
    Please Login or Register  to view this content.
    Have you made any other changes?
    Hi Marcol,

    1. The cell will already have a default or previously stored path, which I do not want to clear, in case the user did not select a new one. The change suggested by you will clear the cell.

    2. No I have not made any change other than that the offset selected is (0,-1).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1