vba 我可以模拟在 Excel 宏中按下 Enter 键吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44730474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 10:51:50  来源:igfitidea点击:

Can I simulate pressing the Enter key in an Excel macro?

excelvbatext-to-speech

提问by Thea

I am using an Excel macro to perform a text-to-speech readout of text in a specific cell:

我正在使用 Excel 宏对特定单元格中的文本执行文本到语音朗读:

Range("$D").Select
Application.Speech.SpeakCellOnEnter = True

This requires the user to press the Enter key after the macro is called for this to be activated. That means two actions by the user, since the macro is called by the user clicking a "Listen" link on the sheet. Is there a way to simulate the Enter key press within the macro? Or is there a better option for text-to-speech?

这需要用户在调用宏后按 Enter 键才能激活它。这意味着用户的两个操作,因为用户单击工作表上的“收听”链接来调用宏。有没有办法在宏中模拟 Enter 按键?或者有没有更好的文本转语音选择?

回答by yass

Include the Sendkeys in your Macro

在宏中包含发送键

Application.SendKeys "{ENTER}" 
Range("$D").Select
Application.Speech.SpeakCellOnEnter = True