VBA - Lock Mouse & Keyboard

AndrewKent

Well-known Member
Joined
Jul 26, 2006
Messages
889
Hi there,

I am currently writing a routine that writes data from Excel to a web-based form. This works successfully but has the slight down-side that if the user closes Internet Explorer (which is what I've automated), then the routine will crash.

I need to know is there a way of locking the keyboard and mouse for the duration of the routine?

Andy
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Having to bump this up in the hope tat someone can help. it's been open for a few days now.
 
Upvote 0
Nevermind, I found how to do it...

Code:
Declare Function BlockInput Lib "USER32.dll" (ByVal fBlockIt As Long) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub MouseKeyboardTest() 'both keyboard and mouse blocked

    BlockInput True ' Turns off Keyboard and Mouse
'   Routine goes here
    Sleep 5000 ' Optional coding
    BlockInput False ' Turns on Keyboard and Mouse
    
End Sub
 
Upvote 0
Will BlockInput disable mouse/keyboard for ALL applications and Windows desktop? Or just Excel?
 
Upvote 0

Forum statistics

Threads
1,214,849
Messages
6,121,922
Members
449,056
Latest member
denissimo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top