2012-05-25 27 views
8

Vorrebbe farlo entro i confini di VBA (altri utenti non hanno altri strumenti di sviluppo da modificare). Sono a conoscenza di app di terze parti (ad esempio iMacros) che eseguono simili, ma vogliono che siano il più possibile generiche. Il negozio usa XP e Excel 2003.VBA WebBrowser cattura schermo intero

(1) A VBA subroutine sta controllando un browser InternetExplorer per automatizzare sito web la visualizzazione, la forma sostiene, ecc

(2) C'è un modo per ottenere una cattura dello schermo dai contenuti del WebBrowser? Senza approcci disordinati SendKeys? .NET ha un metodo Webbrowser.DrawToBitmap ma non riesce a trovare una soluzione facile per VBA. Vuoi l'intero schermo, tra cui "sotto la piega" - al di sotto delle barre di scorrimento ...

+1

PDF qualsiasi uso? Se è così, puoi stampare. – Fionnuala

+0

Sì, è possibile farlo usando le API ma è un po 'complesso. –

+0

+ 1 Nice Question :) –

risposta

10

PROVATO E TESTATO (pasta codice completo in un modulo ed eseguire Esempio Sub()

codice della logica

1) Questo codice viene aperto IE

2) Individuate Google.com

3) Massimizzare IE

4) Acquisisci fotogramma

5) lancio 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 
+0

+1 cool! appena testato e funziona come accennato;) –

+0

Nel mio test, non ottenendo abbastanza solo la pagina web - ottenendo anche le barre di scorrimento, ma è un inizio. Grazie. – SteveValarenti

+0

Sì, sfortunatamente, si otterrà l'istantanea dello schermo completo. È come premere 'PRINTSCREEN' dopo aver massimizzato IE. –

2
Dim objIe As Object 
Set objIe = CreateObject("internetexplorer.application") 
    With objIe 
     .Navigate "www.google.com" 
     '// Set offline JIC user NOT Online 
     .offline = True 
     '// Maximise the Ie window if not Already Max 
     .Visible = True 
     '// This routine used to Maximise Ie 
     ShowWindow objIe.hwnd, SW_MAXIMIZE 
     SetForegroundWindow objIe.hwnd 
    End With 

Public Const SW_MAXIMIZE As Long = 3  'Show window Maximised 
Public Const SW_MINIMIZE As Long = 1  'Show window Minimized 

Public Declare Function ShowWindow _ 
    Lib "user32" (_ 
    ByVal hwnd As Long, _ 
    ByVal nCmdShow As Long) _ 
As Long 

Public Declare Function SetForegroundWindow _ 
    Lib "user32" (_ 
    ByVal hwnd As Long) _ 
As Long