Non seleziona file xls da file IE



  • Non seleziona file xls da file IE
    di Federico (utente non iscritto) data: 07/10/2015 12:00:03

    Salve,
    Ho creato un file excel che mi scaricasse (tramite screenshot e salvataggio immagine) le prove di consegna dal sito della DHL.
    Nello sheet del file excel nella colonna A ho inserito la lista dei numeri DHL e quando lancio la macro una volta che la prima immagine è stata scaricata non viene riselezionato il file excel.
    Il comando Windows("SalvareScreenshot.xls").Activate non sembra funzionare.
    Sapreste aiutarmi?
    GRazie mille,
    Federico
     
    Option Explicit
    
    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 Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
    
    Private Const WM_CLOSE = &H10
    Private Const VK_MENU = &H12
    Private Const VK_SNAPSHOT = &H2C
    Private Const KEYEVENTF_KEYUP = &H2
    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    
    
    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
    
    
    Public Sub SaveImageActiveWindow()
    '////////////////////////////////
    '// Ivan F Moala //
    
    '// For my friend Colo //
    '////////////////////////////////
    
    Dim Altscan As Double
    On Error GoTo ErrHandler
    
    '// Copy picture into the clip board.
    Altscan = MapVirtualKey(VK_MENU, 0)
    keybd_event VK_MENU, Altscan, 0, 0
    
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_MENU, Altscan, KEYEVENTF_KEYUP, 0
    
    Application.Wait Now + TimeSerial(0, 0, 1)
    SavePicture PastePicture(xlBitmap), "C:Users502390548DesktopAWBTest.bmp"
    Exit Sub
    
    ErrHandler:
    '// Error handling
    MsgBox Err.Number & ":= " & Err.Description
    
    End Sub
    
    Private Sub UserForm_Click()
    SaveImageActiveWindow
    MsgBox "Done !"
    End Sub
    
    
    Sub Snapshot()
    
    
        Dim IE As Object
        Dim hwnd As Long, IECaption As String
    
        Set IE = CreateObject("InternetExplorer.Application")
    
        IE.Visible = True
    
        IE.Navigate "INDIRIZZO DELLA DHL" & Cells(2, 1)
    
        Sleep 2000
    
        '~~> Get the caption of IE
        IECaption = "Rintracciare, Rintracciare le spedizioni | Ricerca spedizioni di DHL Express - 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
    Sleep 1000
        DoEvents
    
        '~~> Take a snapshot
        Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
        
        
    '=========ALTRO CODICE=========================
        
        Dim Altscan As Double
    On Error GoTo ErrHandler
    
    '// Copy picture into the clip board.
    Altscan = MapVirtualKey(VK_MENU, 0)
    keybd_event VK_MENU, Altscan, 0, 0
    
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_MENU, Altscan, KEYEVENTF_KEYUP, 0
    
    Application.Wait Now + TimeSerial(0, 0, 1)
    SavePicture PastePicture(xlBitmap), "C:Users502390548DesktopDHL " & Cells(2, 1) & ".bmp"
    Exit Sub
    
    ErrHandler:
    '// Error handling
    MsgBox Err.Number & ":= " & Err.Description
    
    End Sub
    
    
    
    Sub Snapshot1()
    
    
        Dim IE As Object
        Dim hwnd As Long, IECaption As String
        Dim i As String
        i = 2
        
        While i <> ""
    
        Set IE = CreateObject("InternetExplorer.Application")
    
        IE.Visible = True
    
        IE.Navigate "INDIRIZZO DHL" & Cells(i, 1)
      
    
        Sleep 2000
    
        '~~> Get the caption of IE
        IECaption = "Rintracciare, Rintracciare le spedizioni | Ricerca spedizioni di DHL Express - 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
    Sleep 1000
        DoEvents
    
        '~~> Take a snapshot
        Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
        
    
        
        
    '=========ALTRO CODICE=========================
        
        Dim Altscan As Double
    On Error GoTo ErrHandler
    
    '// Copy picture into the clip board.
    Altscan = MapVirtualKey(VK_MENU, 0)
    keybd_event VK_MENU, Altscan, 0, 0
    
    keybd_event VK_SNAPSHOT, 0, 0, 0
    keybd_event VK_MENU, Altscan, KEYEVENTF_KEYUP, 0
    
    Application.Wait Now + TimeSerial(0, 0, 1)
    SavePicture PastePicture(xlBitmap), "C:Users502390548DesktopPOD DHLDHL " & Cells(i, 1) & ".bmp"
    Exit Sub
    
    ErrHandler:
    '// Error handling
    MsgBox Err.Number & ":= " & Err.Description
    
    
    
    Windows("SalvareScreenshot.xls").Activate
    
    i = i + 1
    Wend
    
    End Sub



  • di scossa data: 07/10/2015 13:15:21

    Prova a mettere in fondo alla tua macro

    VBA.AppActivate Application.Caption


    scossa's web site
    Se tu hai una mela, ed io ho una mela, e ce le scambiamo, allora tu ed io abbiamo sempre una mela per uno. Ma se tu hai un'idea, ed io ho un'idea, e ce le scambiamo, allora abbiamo entrambi due idee. (George Bernard Shaw)