vba 函数 "sendkeys" 不发送任何内容

vba function "sendkeys" does not send anything

似乎“sendkeys”只适用于关闭您的号码锁定。它似乎没有做任何其他事情。我尝试了许多不同的方法来简单地将随机字符写入记事本但没有成功。我唯一的预感是最近的 Windows 更新禁用了此功能,因为它在上周之前一直运行良好。下面是一些示例代码。有谁知道如何让它再次发送密钥?

Public Sub WriteToNotePad()

    Dim vReturn As Variant
    vReturn = Shell("NotePad.exe", vbNormalFocus) 'open notepad

    AppActivate vReturn 'ensure notepad is active
    Application.Wait (Now() + TimeValue("00:00:03")) 'wait a few seconds
 
    SendKeys "You should see this in notepad", True
   
End Sub

我使用的计算机未获得 Office 365 更新,代码运行良好。所以我确定这就是问题所在。为了修复它,我使用了 John Coleman 的建议来编写一个 VBS 文件,然后从 VBA 代码中调用该脚本。

从上面的例子,改变这个:

SendKeys "You should see this in notepad", True

为此:

Call Shell("wscript C:\writeToNotepad.vbs", vbNormalFocus)

并且 VBS 文件将以该名称和以下内容保存在该位置:

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "You should see this in notepad"