However, one of the issues with VBA -- at least until now -- is the fact that an end user can inadvertly press CTRL+Break (older keyboards) or CTRL+C and stop the execution of a script. Now imagine if that script is say, some code developed to calculate 401K contributions when payroll is ran... the results will certainly not be pretty!
With this in mind, we can use a USER32.DLL library funcion to disable user input when critical VBA code is required to be executed in a block. The following shows how to implement such code:
BlockInput function
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As
Long
We can now use this function across any of our VBA customizations, as follows:
Sample Window_BeforeOpen code
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
BlockInput True
' All the code you need to run here
...
' MAKE SURE TO RE-ENABLE THE INPUT
BlockInput False
End Sub
There are several applications for this code, but whatever you do, don't forget to re-enable the user input, otherwise you will end up with one dead mouse and keyboard!
Until next post!
MG.-
Mariano Gomez, MVP
Maximum Global Business, LLC
http://www.maximumglobalbusiness.com/

Like
Report
*This post is locked for comments