VBA Events


  • Source Module: [Public] Event [identifier]([argument_list])

  • Handler Module: Dim|Private|Public WithEvents [identifier] As [type]


  • An event can only be Public. The modifier is optional because class module members (including events) are implicitly Public by default.

  • A WithEvents variable can be Private or Public, but not Friend. The modifier is mandatory because WithEvents isn't a keyword that declares a variable, but a modifier keyword part of the variable declaration syntax. Hence the Dim keyword must be used if an access modifier isn't present.