How can I detect that an excel cell has been clicked

B

Ballantine

I have a vb.net app which includes an excel sheet. I need to detect when a
cell has been clicked but there does not appear to be an appropriate event to
handle.

So far I have handled the "XLSheet.SelectionChange" event to achieve my
requirements BUT if the cell in question is ALREADY selected, clicking on it
will not raise the above event. I have to click elsewhere so that the
selection changes, the result being that data is added to the worksheet in
the "wrong" cell.

Am I missing something that should be really obvious?

I am using vb.net express (2008) and Office 2007 (interop).
 
B

Barb Reinhardt

In 2003, there is a Worksheet_SelectionChange that triggers when a cell is
selected.
 
B

Ballantine

Thanks for showing some interest and very promptly too. Unfortunately you
are only telling me what I already know. Hopefully someone else will have
come across the same issue and will tell us how they overcame it.
 
B

Barb Reinhardt

After you trigger the selection change event, could you do something like
this so you could select the same cell again

Application.EnableEvents = FALSE
Target.parent.cells(1,1).select
Application.EnableEvents = TRUE
 
B

Ballantine

Thanks again, Barb. Your suggestion is useful. However, since the
worksheets being used by my app might reasonably have 200+ x 200+ used cells
I don't want to navigate away from the most recently selected cell.
Obviously I could use a "nearby" cell but this workaround starts to get
over-complicated when you apply logic to determine an appropriate cell to
select - I don't want the range of cells being displayed to change.

I must admit, however, that I didn't think of turning event handling off/on.
Far too obvious for me!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top