如何使用VBA截取网页的截图? [英] How to take screenshot of webpage using VBA?
本文介绍了如何使用VBA截取网页的截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Excel中使用VBA截图。
问题是,屏幕截图只能通过按下键盘的F6键,因为Screenhunter用于此目的。
打印屏幕键禁用。
我使用以下代码,但意识到sendkey函数无法使用:
sub test()
application.sendkeys{F6}
end sub
< 解决方案
p>我在最大化屏幕后添加了一些延迟,创建了一个Word文档并粘贴了其中的屏幕截图。其余的代码取自Siddharth提供的链接。 私有声明子keybd_event Libuser32(ByVal bVk As Byte,ByVal bScan As Byte,ByVal dwFlags As Long,ByVal dwExtraInfo As Long)
私有声明Sub Sleep Libkernel32.dll(ByVal dwMilliseconds As Long)
私有Const VK_SNAPSHOT As Byte = 44
私有声明函数FindWindow Libuser32别名FindWindowA(ByVal lpClassName As String,ByVal lpWindowName As String)As Long
私有声明函数ShowWindow Libuser32(ByVal hwnd As Long,ByVal nCmdShow As Long)As Long
Private Const SW_SHOWMAXIMIZED = 3
Private Const VK_LCONTROL As Long =& HA2
Private Const VK_V =& H56
Private Const KEYEVENTF_KEYUP =& ; H2
Sub Sample()
Dim IE As Object
Dim hwnd As Long,IECaption As String
设置IE = CreateObject(InternetExplorer应用程序)
IE.Visible = True
IE.Navigatewww.Google.com
袖子p 5000
'~~>获取IE
的标题IECaption =Google - Internet Explorer
'~~>获取处理IE
hwnd = FindWindow(vbNullString,IECaption)
如果hwnd = 0然后
MsgBoxIE窗口未找到!
退出子
Else
'~~>最大化IE
ShowWindow hwnd,SW_SHOWMAXIMIZED
如果
睡眠3000
DoEvents
'~~>拍一张快照
调用keybd_event(VK_SNAPSHOT,0,0,0)
'~~>开始Word
设置wordobj = CreateObject(Word.Application)
设置objDoc = wordobj.Documents.Add
wordobj .Visible = True
设置objSelection = wordobj.Selection
'粘贴到Word
objSelection.Paste
End Sub
How to take screenshot of webpage using VBA in excel.
The problem is that screen shots can be taken only by pressing F6 key of keyboard since Screenhunter is used for this purpose.
The print screen key is disabled.
I used the following code but realised that sendkey function can not be used:
sub test()
application.sendkeys "{F6}"
end sub
Please Help.
解决方案 I have added some delay after maximizing the screen, created a Word Doc and pasted the screen shot in it. The rest of the code is taken from the link which Siddharth has provided.
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Const VK_SNAPSHOT As Byte = 44
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_SHOWMAXIMIZED = 3
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_V = &H56
Private Const KEYEVENTF_KEYUP = &H2
Sub Sample()
Dim IE As Object
Dim hwnd As Long, IECaption As String
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "www.Google.com"
Sleep 5000
'~~> Get the caption of IE
IECaption = "Google - Internet Explorer"
'~~> 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
Sleep 3000
DoEvents
'~~> Take a snapshot
Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
'~~> Start Word
Set wordobj = CreateObject("Word.Application")
Set objDoc = wordobj.Documents.Add
wordobj.Visible = True
Set objSelection = wordobj.Selection
'Paste into Word
objSelection.Paste
End Sub
这篇关于如何使用VBA截取网页的截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文