0

I wrote this code, it should run when the Enter key is pressed. However its not happening.
As I know I need to put this code on this "ThisDocument" [clipping of a Windows Explorer window](https://i.stack.imgur.com/bWolr.png)

Private Sub Document_KeyPress(ByVal KeyAscii As Integer)
    If KeyAscii = 13 Then
        ' This code will run when the Enter key is pressed
        MsgBox "Enter key pressed"
    End If
End Sub


I wrote this code and tried to run.

greybeard
  • 2,249
  • 8
  • 30
  • 66
Salim
  • 1
  • 2

1 Answers1

0

does word document has a event when some changes was done in this document ?

Yes. You have to use the class module to initiate it, not ThisDocument object. And there is no event name Document_KeyPress, because the Word Document object is not MS Form object. You can refer to Application object and Using events with the Application object for further info. For the implementation example, you can refer to my answers also. like this one.

enter image description here

Oscar Sun
  • 1,427
  • 2
  • 8
  • 13