Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-26-2023, 09:27 AM
coffent coffent is offline Using SendKeys in a VBA subroutine toggles NumLock Windows 10 Using SendKeys in a VBA subroutine toggles NumLock Office 2019
Advanced Beginner
Using SendKeys in a VBA subroutine toggles NumLock
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default Using SendKeys in a VBA subroutine toggles NumLock

I have added a subroutine call to the context-sensitive right-click menu in Excel. For purposes of my question, I've reduced the subroutine to:



Sub Test()
SendKeys("x")
End Sub

In this case, the subroutine simply puts an "x" in the active cell. However it inexplicably also toggles the NumLock status (from on to off or from off to on). No matter what keys are substituted for "x", NumLock is toggled. The only SendKeys statement that doesn't toggle NumLock is SendKeys(""), i.e., a null.

What could be causing this bizarre behavior?
Reply With Quote
  #2  
Old 01-26-2023, 09:46 AM
p45cal's Avatar
p45cal p45cal is offline Using SendKeys in a VBA subroutine toggles NumLock Windows 10 Using SendKeys in a VBA subroutine toggles NumLock Office 2019
Expert
 
Join Date: Apr 2014
Posts: 863
p45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant futurep45cal has a brilliant future
Default

Don't use the parentheses:
Sendkeys "x"
Reply With Quote
  #3  
Old 01-26-2023, 10:36 AM
coffent coffent is offline Using SendKeys in a VBA subroutine toggles NumLock Windows 10 Using SendKeys in a VBA subroutine toggles NumLock Office 2019
Advanced Beginner
Using SendKeys in a VBA subroutine toggles NumLock
 
Join Date: Dec 2019
Posts: 40
coffent is on a distinguished road
Default Fixed with workaround

Removing parentheses makes no difference.

However digging further I've found this is a known problem with SendKeys. For example, see Excel VBA - make sure Numlock is always ON - Stack Overflow

I've set up a clumsy workaround, so I'll move on.
Reply With Quote
Reply

Tags
numlock, sendkeys

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex Document Templates with Section Toggles and Multiple Fields damaniam Word 1 06-04-2019 06:49 PM
Using SendKeys in a VBA subroutine toggles NumLock SENDKEYS with vbYesNoCancel and Select Case kiwimtnbkr Word VBA 31 06-11-2018 04:56 AM
Using SendKeys in a VBA subroutine toggles NumLock Function or subroutine with counting memory paik1002 Word VBA 1 12-15-2015 01:28 AM
Using SendKeys in a VBA subroutine toggles NumLock A macro that can insert FILENAME, sendkeys CTRL ALT T, paste clipboard, and nextline kyjac85 Word VBA 13 09-20-2012 05:00 PM
Problem with the sendkeys in Win7 vidyapakki Excel Programming 1 05-07-2012 11:10 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:05 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft