【发布时间】: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