【问题标题】:IE automation VBA, delay in sending keys using sendkeys instantlyIE自动化VBA,立即使用sendkeys发送密钥延迟
【发布时间】:2012-10-22 07:46:21
【问题描述】:

我编写了一个代码,用于在网页导航时拍摄屏幕截图,并使用 VBA 将其粘贴到 Word 文档中,我成功地做到了,但我得到的是上次而不是现在的屏幕截图。

例如,每当我按下 printscreen 时,它都会粘贴上次拍摄的屏幕截图,而不是现在的截图。我试着做延迟,并把论据设为真,假没有任何效果。

这是我在 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

在一个模块中

Sub initialise()
Set ev = New Class1
ev.Example

End Sub

【问题讨论】:

  • Sendkeys 不可靠。请参阅此链接。这就是你想要的。 stackoverflow.com/questions/10759580/… 我在 MSPaint 中粘贴。可以粘贴到word中
  • 你不需要那个部分。那是在 PaintBrush 中粘贴。图像已经在剪贴板中。您可以使用Selection.Paste将其粘贴到word中。
  • @SiddharthRout 它不起作用,即使在使用 keybd_event 后它也会粘贴旧的,你能运行我的代码并给出解决方案吗?请
  • @SiddharthRout 嗨,sidharth 请帮帮我..
  • @SiddharthRout 嗨,您的解决方案不起作用朋友请给我其他解决方案

标签: vba excel sendkeys webautomation


【解决方案1】:

试试 Application.SendKeys "{44}", True

第二个参数告诉代码的执行等待动作完成

【讨论】:

  • 我什至尝试过 Appliication.SendKeys "{44}",即使那样它的工作方式也是如此,请执行我提供的代码并帮助我获得解决方案,它很紧急。
【解决方案2】:

经过所有的努力,我想出了这个解决方案,我只是让粘贴选项等待 3 秒,直到图片被加载到剪贴板......:) 带有 true 选项的 sendkeys 根本不起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多