ESTRARRE DATI DA PAGINA WEB



  • ESTRARRE DATI DA PAGINA WEB
    di Robert (utente non iscritto) data: 03/02/2016 09:43:35

    buongiorno a tutti,
    ho un problema con uno script che ha lo scopo di salvare su fogli Excel dati presenti su un sito WEB.
    le info sono in forma di tabelle presenti su più pagine.

    lo script funziona egregiamente salvo che si blocca su .connection = MyURL, basta dare invio e procede regolarmente. se di effettua il debug e si fanno passare passo passo le istruzioni non si blocca. se nel debug tengo premuto F8 si blocca al solito posto.

    ho provato ad inserire uno sleep ma non cambia nulla. utilizzo Excel 2013

    grazie anticipatamente per la collaborazione.


     
    Sub Macro1()
    
    Dim MyPage As String
    Dim MyURL As String
    Dim EndPath As String
    Dim MyFile As String
    
    
    COUNTER = 0
    
    
    inizio_procedura:
    
    
    COUNTER = COUNTER + 1
    
    
    MyFile = "foglio1.xlsx"
    
    
    MyPage = COUNTER
    
    
    MyURL = "URL;h t t p://w w w.centricommerciali.it/risultati_1024x768.cfm?PageNum_tutte_tabelle=" & MyPage & "&®ioni=Tutte_le_Regioni&provincia=&libero=&Submit=Invia"
    
    
    '
    With ActiveWorkbook.Connections("Connessione")
    .Name = "Connessione"
    .Description = ""
    End With
    Range("A1:D11").Select
    With Selection.QueryTable
    'Sleep 1000
    .Connection = MyURL
    '.CommandType = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = """tutte"""
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With
    Range("A1").Select
    ActiveWorkbook.Connections("Connessione").Refresh
    
    
    
    Range("A1:D11").Select
    Range("D11").Activate
    Selection.Copy
    Workbooks.Add
    ActiveSheet.Paste
    Application.CutCopyMode = False
    ChDir "C:"
    ActiveWorkbook.SaveAs Filename:= _
    MyFile, FileFormat:= _
    xlOpenXMLWorkbook, CreateBackup:=False
    ActiveWindow.Close
    
    EndPath = "C:foglio1.xlsx"
    
    Kill EndPath
    
    
    'Resume
    GoTo inizio_procedura
    
    
    End Sub