I have a barcode scanner. So when the barcode is scanned using a gun, the value normally is entered to textfield placed on the screen.
So I have made an excel macro. And when the barcode is scanned, the text appears on the cell ending with the new line character (text+”\r\n” is provided by the scanner itself). So an event is triggered and does the rest.
The problem is that the event is only triggered with a new line character. What if the barcode scanner didn’t provide \r\n after every barcode output. How do I deal with such situations?
How do I detect it and trigger event?
If you create a userform to take the input, you can use the
keydownorkeypressevents to detect keys pressed. You would have to know what the end condition of the barcode would be, so you know when to send the value to the cell to be processed.Keydown will give you shift state, and also capture pageup/pagedown/other special keys
Keypress will only work with keys that produce a typeable character
Without userforms, you will have to rely on enter/newline to trigger the
Changeevent in the worksheet