Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    Estrarre dati da oggetto

    Ciao ragazzi,

    ho un problema con una sub che sto facendo.

    Praticamente il codice che mi accingo a postare apre una serie di indirizzi del tipo:

    http://maps.google.com/maps?saddr=-3...3.1139,151.514

    da un foglio di excel.

    Quando la pagina si apre mostra tra le varie cose la distanza tra due coordinate.

    La mia sub prende la pagina web ed estrae il contenuto dei tag di tipo SPAN mettendoli in una object collection.

    Ora non ci crederete ma dopo avere fatto tutto sto sbattimento non riesco ad estrarre nulla dall'oggetto "objCollection".

    Sto usando Target = objCollection(i).Value per estrarre la stringa che mi interessa ma ricevo il seguente errore:

    Run-time error '438':
    Object doesn.t support this property or method

    In pratica la domanda e': "ma come cavolo si estrae una stringa dalla collection che ho fatto?"

    allego qui sotto il codice:

    codice:
    Sub Test()
        
        Dim lngLastRow As Long
        Dim lngLoopCtr As Long
        Dim ie As Object
        Dim location As String
        Dim i As Integer
        Dim sFileName As String
        Dim iFileNum As Integer
        Dim sBuf As String
        Dim Fields As String
        Dim Target As String
        Dim objCollection As Object
        Dim objElement As Object
        
        Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
        
        lngLastRow = Range("G" & Rows.Count).End(xlUp).Row
        
        Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
        
        For lngLoopCtr = 2 To lngLastRow Step 1
        
            If Cells(lngLoopCtr, "G") = "" Then
                Cells(lngLoopCtr, "G").Select
                Exit For
                
            End If
            
               Cells(lngLoopCtr, "G").Select
                
               location = Cells(ActiveCell.Row, "G")
               
               ie.navigate location
               ie.Visible = True
    
               
                   While ie.Busy
                   Application.Wait DateAdd("s", 1, Now)
                   DoEvents
                   Wend
                                              
                      Set objCollection = ie.document.getElementsByTagName("SPAN")
                            
                   i = 0
                                 
                   While i < objCollection.Length
                                 
                            ' Set text for search
    
                    'Target = objCollection(i).Value
    
                     i = i + 1
    
                  Wend
    
            Application.Wait Now + TimeValue("00:00:04")
             
        Next lngLoopCtr
        
    End Sub

    Grazie a Presto.

  2. #2

    Moderazione

    Stiamo parlando di VBA?
    Amaro C++, il gusto pieno dell'undefined behavior.

  3. #3
    Ciao,

    Si sfortunatamente non sto facendo sta cosa in Java altrimenti non avrei molti problemi.

    Ciao ancora e grazie

  4. #4
    getElementsByTagName restituisce un IHTMLElementCollection, di cui credo tu debba usare il metodo item per accedere ai valori in esso contenuti. Tenterei quindi:
    codice:
                    Target = objCollection.item(i).Value
    (tutto questo al condizionale, non so se VBA vedendo un'interfaccia che supporta un metodo item non tenti già di richiamarlo quando si usa la sintassi-array)
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.