+ Reply to Thread
Results 1 to 7 of 7

Formating fetched data from web in VBA

Hybrid View

devilhack Formating fetched data from... 11-20-2012, 03:54 AM
Kyle123 Re: Formating fetched data... 11-20-2012, 05:04 AM
devilhack Re: Formating fetched data... 11-20-2012, 05:37 AM
devilhack Re: Formating fetched data... 11-20-2012, 06:09 AM
Kyle123 Re: Formating fetched data... 11-20-2012, 05:40 AM
Kyle123 Re: Formating fetched data... 11-20-2012, 06:15 AM
Kyle123 Re: Formating fetched data... 11-20-2012, 06:17 AM
  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Exclamation Formating fetched data from web in VBA

    Hi guys,

    i was looking a macro to fetch table from http://www.flipkart.com/canon-powers...f-5af8eb547815 and i did but the data fetch by the macro saves in single row. I want the table in the same format.
    I tried many things but didnt work.
    This is the script im using
    Sub Extract_TD_text()
    
        Dim URL As String
        Dim IE As InternetExplorer
        Dim HTMLdoc As HTMLDocument
        Dim TDelements As IHTMLElementCollection
        Dim TDelement As HTMLTableCell
        Dim r As Long
        
        URL = Range("sURL")
        
        Set IE = New InternetExplorer
        
        With IE
            .navigate URL
            .Visible = True
        
            'Wait for page to load
            While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Wend
        
            Set HTMLdoc = .document
        End With
        Set TDelements = HTMLdoc.getElementsByTagName("table")
        r = 0
        For Each TDelement In TDelements
            'Look for required TD elements - this check is specific to VBA Express forum - modify as required
            If TDelement.className = "fk-specs-type2" Then
            Sheet1.Range("A2").Offset(r, 0).Value = TDelement.innerText
                r = r + 1
            End If
        Next
                
    End Sub
    Thanks in Advance
    -
    AND I KNOW ITS EASY FOR YOU GUYS & IM JUST A NOOB
    Last edited by devilhack; 11-20-2012 at 06:10 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Formating fetched data from web in VBA

    Why not use a web query? Data > From Web

    No need to use VBA then

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Formating fetched data from web in VBA

    Hei. I already tried that but i want fectch same data from 100s of link and the data links are on the same location.
    This script work perfectly till formatting comes. all the table data save is in one Row...

    plz help me out

  4. #4
    Registered User
    Join Date
    10-10-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Formating fetched data from web in VBA

    Book1.xlsm
    HI attached and example what i actually want to do.
    I hope it helps.

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Formating fetched data from web in VBA

    You could have a script that loops through the urls and creates a webquery for each one?

    What sort of formatting are you talking about? The font/colour etc or the layout?

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Formating fetched data from web in VBA

    It still doesn't answer my question as to why you don't just use a web query and write code to loop through.

    You're getting formatting like that since you aren't looping through table cells, you are looping through tables, so what you are calling TDElements are actually tables, not TDs.

    Therefore when you extract the inner text of the TDElement, it is the text for the entire table, not the text for the td. You need to loop through all the rows and all the cells also, so you need another 2 nested loops.

  7. #7
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Formating fetched data from web in VBA

    bump for dodgy server reasons - shows I haven't replied
    Last edited by Kyle123; 11-20-2012 at 06:24 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1