Question : How do we intecept events in excel VIA VBA

We would like to have a way of editing the contents of an excel work sheet cell after the user exits the cell.

Is there some way to get a "lost focus" event (or something similar) when the user exits a cell on a sheet?

250 pts for an answer

Answer : How do we intecept events in excel VIA VBA

Hi cschene,
The Worksheet_SelectionChange event sub is triggered when the user changes the cell selection. If you have previously stored the old selection in a static variable, then you can have the effect of a sub that runs on a "lost focus" event.

This sub must go in the code pane for the worksheet being watched. It will display a messagebox with the address of the previous selection.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static oldTarget As Range
If oldTarget Is Nothing Then
    Set oldTarget = Target
Else
    MsgBox oldTarget.Address    'Your "lost focus" sub could be called here
    Set oldTarget = Target
End If
End Sub

To install a sub in the code pane for a worksheet:
1) Right-click the sheet tab for the worksheet
2) Choose View Code from the resulting pop-up
3) Paste the suggested code in the resulting module sheet
4) ALT + F11 to return to the worksheet

If the above procedure doesn't work, then you need to change your macro security setting. To do so, open the Tools...Macro...Security menu item. Choose Medium, then click OK.

Cheers!

Brad
Random Solutions  
  •  Outlook 2003 POP-to-IMAP disappointment, is Exchange Server hosting  the solution?
  •  dissallow / ban decimal (period) character in text field in Livecycle
  •  Open MS Office documents within relevant application when downloaded from intranet
  •  object library invalid contains references to object definitions that could not be found
  •  How do I fully clear and rebuild a full-text search catalog in SQL 2005 Express
  •  magento how do I display all the products in a single page?
  •  Quality banner exchange network
  •  Stop Adsense Security Error: Content at <a rel="nofollow" href="http://googleads.g.doubleclick.net/" target="_blank">http://googleads.g.doublec<wbr />lick.net/</a> may not load data from...
  •  Boot Problem....Hard Disk Command Failed
  •  Trying to edit fRSMemberReferenceBL with ADSI Edit and get error attribute owned by system
  •  
    programming4us programming4us