IE 自动化 VBA,立即使用 sendkeys 延迟发送密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13181877/
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
IE automation VBA, delay in sending keys using sendkeys instantly
提问by nothingisimpossible
I have written a code to take screen shots whenever webpage navigates and paste it in Word document using VBA, I succeeded in doing that but I am getting the screen shots that took last time instead of present one.
我已经编写了一个代码来在网页导航时使用 VBA 将其粘贴到 Word 文档中时进行屏幕截图,我成功地做到了这一点,但我得到的是上次拍摄的屏幕截图而不是当前的屏幕截图。
Example whenever I press printscreen it is pasting screen shot took last time instead of present one. I tried doing delays and making the argument to true, false nothing worked.
例如,每当我按下打印屏幕时,它都会粘贴上次拍摄的屏幕截图而不是当前的截图。我试着拖延并把论点设为真,假没有任何效果。
This is what I have tried in Class1 module:
这是我在 Class1 模块中尝试过的:
Option Explicit
Dim WithEvents ie As InternetExplorer
Dim wordapp As Object
Dim wrdDoc As Object
Dim t As Date
Sub Example()
Set wordapp = CreateObject("word.Application")
wordapp.Visible = True
Set wrdDoc = wordapp.Documents.Add
Set ie = New InternetExplorer
ie.navigate "http://www.csee.wvu.edu/~riggs/html/select_example.html"
Do Until ie.readyState = READYSTATE_COMPLETE: DoEvents: Loop
test
End Sub
Private Function href_onclick() As Boolean
Application.SendKeys "{44}"
wordapp.Selection.Paste
End Function
in a module
在一个模块中
Sub initialise()
Set ev = New Class1
ev.Example
End Sub
回答by CSharpie
try Application.SendKeys "{44}", True
试试 Application.SendKeys "{44}", True
The Second parameter tells the execution of the code to wait for the action to complete
第二个参数告诉执行代码等待动作完成
回答by nothingisimpossible
After all struggling i came up with this solution, I just made the paste option to wait for 3 secs till the picture gets loaded into the clipboard ....:)sendkeys with true option doesn't work at all.
在我苦苦挣扎之后,我想出了这个解决方案,我只是让粘贴选项等待 3 秒,直到图片加载到剪贴板中....:)sendkeys with true 选项根本不起作用。