我正在尝试启动一个 URL,然后截取打开的 IE 窗口的屏幕(启动 URL 时它还会启动智能卡阅读器应用程序),因此我需要它捕获所有打开的窗口或 IE 窗口,然后将其作为图像粘贴到下面的单元格中或作为图像保存到 C 盘,然后我就可以将该文件附加到工作簿。
我正在尝试让此代码适用于启动的特定屏幕,我让它工作了一半,但它捕获了错误的应用程序。
Sub Screenshot()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
Dim IE As Object
Dim hwnd As Long, IECaption As String
Dim fdate As Date
'~~> Change Status and unmerge
Range("B11").Value = "Running"
ThisWorkbook.Sheets("SAT").Range("B18:D33").UnMerge
'~~> Launch URL
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "https://www.google.co.uk"
Sleep 5000
'~~> Get the caption of IE
IECaption = "Google - Internet Explorer"
Sleep 4000
'~~> Get handle of IE
hwnd = FindWindow(vbNullString, IECaption)
If hwnd = 0 Then
MsgBox "IE Window Not found!"
Exit Sub
Else
'~~> Maximize IE
'ShowWindow hwnd, SW_SHOWMAXIMIZED
End If
DoEvents
'~~> Snapshot of window & Paste into Sheet location (Esc used to close an application popup screen)
Sleep 1000
keybd_event vk_Escape, 0, 0, 0
Sleep 2000
Application.SendKeys "(%{1068})"
Sleep 2000
Application.SendKeys ("%{F4}")
ThisWorkbook.Sheets("SAT").Range("B18").Select
ActiveSheet.Paste
'~~> Tidy up and update status
Sheets("SAT").Range("B18:D33").Merge
Range("B11").Value = "Completed: Screen Captured"
End Sub
但是我遇到一个问题,它没有说未选择屏幕,然后无法粘贴到底部的 B18,需要我调试“ActiveSheet.Paste”部分。
它非常接近,任何帮助都将非常感激。