简体   繁体   中英

How to detect if ctrl + enter in an Excel spreadsheet with VBA

My understanding is: Macro canNOT be activated while a cell is active for editing.

I notice by hitting ctrl + enter , the cell is de-activate for editing but remain selected. I would like then to run some macro refer to this cell.

Therefore, using VBA, how to detect if ctrl + enter is pressed?

Easiest way should be using the Change event of the worksheet.
This would not (only) detect a ctrl + enter but any change of a cell.

Private Sub Worksheet_Change(ByVal Target As Range)

End Sub

This sub has to be added to the worksheets code (not into a module)!


Another approach would be using the OnKey Method

 Application.OnKey "^{RETURN}", "InsertProc" 

See here for a decent explanation: Application.OnKey Method (Excel)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM