What code does: I have a code that moves the mouse around the screen, takes printscreens and pastes it to excel.
Problem: For some reason, my code always (with absolutely no exceptions) turns the NUMLOCK key off after every run.
What I tried so far: I searched around and found the SendKeys (NUMLOCK), which in theory works (although it seems to be very problematic for users).
What I want to do: I want to turn the NUMLOCK on after each macro run,
Obs1: I have no idea what is causing the macro to turn it off in the first place. Fixing whatever is causing this would be ideal, but since I have no idea what the problem is, I first want to get my code functional. I am going to work on that as soon as find a way to turn the NUMLOCK key on.
Question: Can I do this using the SendKeys? Am I using it properly? Is there a better way?
Obs2: Since it is a much bigger code, as soon as this is solved, I am going to post another question with the entire code, and go over on what is causing the problem.
Code I am trying to sue to turn numlock on:
Application.Sendkeys (NUMLOCK)
Also tried:
Application.Sendkeys ("NUMLOCK")
and
Application.Sendkeys {NUMLOCK}
You almost had it! The correct coding is: Application.Sendkeys ("{NUMLOCK}")
You can set the keystate directly with a couple of Windows API calls. Ported from the MSDN page for keybd_event function:
Call it like this:
I found this solution so far the best and does not interfere with NUMLOCK. Put below code in a module and call it from anywhere in your project. The script object overwrites the SendKeys in VBA.
I found it in below thread:
SendKeys() permission denied error in Visual Basic
First of all, Copy and paste the following code in your Excel Sheet’s Module (Ex:-Module-1)...
Then, Copy and Paste the following in your Sheet's Code (Ex:- Sheet1 (Code))...
Now Chill!!! For Each SelectionChange you make, Excel Refreshes itself and It makes sure that Numlock is On Always. Replace "Capslock" instead of Numlock if you need it so as the case may be.
Thanks. Sashi Elit :)