VBA web浏览器捕捉全屏 [英] VBA WebBrowser capture full screen

查看:258
本文介绍了VBA web浏览器捕捉全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想做到这一点VBA的范围内(其他用户没有其他的开发工具来修改)。我知道,做类似的,但希望有这种尽可能通用的第三方应用程序(iMacros的,例如)的。车间使用XP和Excel 2003。

Would like to do this within the confines of VBA (other users have no other development tools to modify). Am aware of 3rd party apps (iMacros, for example) that do similar but want to have this as generic as possible. The shop uses XP and Excel 2003.

(1) VBA子程序被控制的浏览器的InternetExplorer自动浏览网页,提交表单等。

(1) A VBA subroutine is controlling an InternetExplorer browser to automate viewing website, form submits, etc.

(2)有没有办法让从web浏览器内容的屏幕捕获?没有杂乱的SendKeys方法? .NET有一个Webbrowser.DrawToBitmap方法,但找不到VBA一个简单的解决方案。希望整个屏幕,其中包括下折 - 下面的滚动条...

(2) Is there a way to get a screen capture from the contents of the WebBrowser? Without messy SendKeys approaches? .NET has a Webbrowser.DrawToBitmap method but can't find an easy solution for VBA. Want the entire screen, including "below the fold" - below the scroll bars...

推荐答案

尝试和测试(在一个模块中粘贴完整code和运行子样品()

code LOGIC

1):此code将打开IE

1) This code will open IE

2)导航到Google.com

2) Navigate to Google.com

3)最大化IE

4)拍摄快照

5)启动MSPAINT

5) Launch MSPaint

6)粘贴在MSPAINT

6) Paste in MSPaint

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 - Windows 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

    DoEvents

    '~~> Take a snapshot
    Call keybd_event(VK_SNAPSHOT, 0, 0, 0)

    '~~> Start Paint
    Shell "C:\Windows\System32\mspaint.exe", vbNormalFocus

    Sleep 3000

    '~~> Paste snapshot in paint
    keybd_event VK_LCONTROL, 0, 0, 0
    keybd_event VK_V, 0, 0, 0
    keybd_event VK_V, 0, KEYEVENTF_KEYUP, 0
    keybd_event VK_LCONTROL, 0, KEYEVENTF_KEYUP, 0
End Sub

这篇关于VBA web浏览器捕捉全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆