Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
624 views
in Technique[技术] by (71.8m points)

internet explorer 8 - VBA WebBrowser capture full screen

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) A VBA subroutine is controlling an InternetExplorer browser to automate viewing website, form submits, etc.

(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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

TRIED AND TESTED (Paste complete code in a module and run Sub Sample()

CODE LOGIC

1) This code will open IE

2) Navigate to Google.com

3) Maximize IE

4) Take snapshot

5) Launch 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:WindowsSystem32mspaint.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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...