vba SendKey 字符串 + 同时输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24930098/
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-12 03:58:04  来源:igfitidea点击:

SendKey string + enter at the same time

vbasendkeys

提问by Révész Marco

Is it possible to send a string and an enter with SendKeys?

是否可以发送一个字符串和一个输入SendKeys

I tried this:

我试过这个:

Application.SendKeys "String? {ENTER}"

What am I doing wrong?

我究竟做错了什么?

回答by Révész Marco

You should be fine submitting each key seperately, at least that is how i have done it when i have used send keys recently;

您应该可以单独提交每个密钥,至少我最近使用发送密钥时是这样做的;

Application.SendKeys "MyString"
Application.SendKeys "{ENTER}"

回答by caveman

I'm using excel 2013 and this works for me

我正在使用 excel 2013,这对我有用

Sendkeys "12345" & "{ENTER}"

发送键“12345”和“{ENTER}”

It will output the 12345 and do a carriage return..
Makes the code a little cleaner to have all the text on one line for putty purposes

它将输出 12345 并执行回车..
使代码更简洁,将所有文本放在一行上用于腻子目的

回答by R.Joshi

Previously I have succesfully used a variation of the code below. My code did not the Application. code. This should concatenate the two strings.

以前我成功地使用了以下代码的变体。我的代码没有应用程序。代码。这应该连接两个字符串。

Application.Sendkeys "myString" + "{ENTER}"

Tested

已测试

SendKeys "myString" + "{ENTER}"

on Excel 2016 and it does work.

在 Excel 2016 上,它确实有效。