Getting text from web to excell

martiano

New Member
Joined
Oct 30, 2010
Messages
11
Hi

I have In columns A urls, I want to export all text from this web urls into the column B.
36014392.jpg


How can I do that? Can I use some function? I hope I don need to use Visual Basic, cos I dont know work with that.


I already know how to import data from ONE web site as is showed in this video http://www.youtube.com/watch?v=m_6s8n1Eeto&feature=related but how can I make it if I have more wbe sites?

Thanks
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I don't think you can do this without VBA code. You would have one web query and VBA code to loop through the list of URLs, refreshing the web query for each URL and copying the required text to the column B cell. It's best to have the web query retrieving data to a separate sheet.

What do you mean by 'full text'? Do you want all the text from one of the web pages to go into one cell?
 
Upvote 0
Try this. Put the code in a standard module (please Google if you don't know how).
Code:
Option Explicit

Public Sub Get_Web_Data()
    
    Dim webQuery As QueryTable
    Dim lastRow As Long
    Dim cell As Range
    
    'Create the web query on Sheet3
    
    Set webQuery = Create_Web_Query(Sheets("Sheet3"))
    
    'Sheet1 contains the list of URLs in column A starting at A2
    
    With Sheets("Sheet1")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        For Each cell In .Range("A2:A" & lastRow)
            cell.Offset(0, 1).Value = ""
            
            webQuery.Connection = "URL;" & cell.Value
            webQuery.Refresh BackgroundQuery:=False

            'Copy price from last row but one in column D on web query sheet
            
            With webQuery.Parent
                lastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
                If lastRow <> 1 Then cell.Offset(0, 1).Value = webQuery.Parent.Cells(lastRow - 1, "D")
            End With
            
            DoEvents
        Next
        
    End With
    
End Sub


Private Function Create_Web_Query(wqSheet As Worksheet) As QueryTable

    Dim i As Integer
    
    'Delete all queries on web query sheet
    
    With wqSheet
        For i = .QueryTables.Count To 1 Step -1
            .QueryTables(i).Delete
        Next
        .Cells.ClearContents
    End With

    Set Create_Web_Query = wqSheet.QueryTables.Add(Connection:="URL;", Destination:=wqSheet.Range("A1"))
    
    With Create_Web_Query
        .Name = "sokker.org"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
    End With
    
End Function
Your example URL actually has 2 transfers for me. From your screenshot I assume you want the value without brackets of the last one, and this is what I've coded.
 
Upvote 0
Read your PM... You want to extract the top price from the web query data rather than the bottom price.

The modification is simple, if I'm right in assuming that the price you want is always in cell D2 on the web query sheet. Therefore try this, which replaces the code above:
Code:
Option Explicit

Public Sub Get_Web_Data()
    
    Dim webQuery As QueryTable
    Dim lastRow As Long
    Dim cell As Range
    
    'Create the web query on Sheet3
    
    Set webQuery = Create_Web_Query(Sheets("Sheet3"))
    
    'Sheet1 contains the list of URLs in column A starting at A2
    
    With Sheets("Sheet1")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        
        For Each cell In .Range("A2:A" & lastRow)
            cell.Offset(0, 1).Value = ""
            
            webQuery.Connection = "URL;" & cell.Value
            webQuery.Refresh BackgroundQuery:=False

            'Copy price from column D on web query sheet
            
            With webQuery.Parent
            
                'Original code - required price is in last row but one in column D
                
                'lastRow = .Cells(.Rows.Count, "D").End(xlUp).Row
                'If lastRow <> 1 Then cell.Offset(0, 1).Value = .Cells(lastRow - 1, "D")
                
                'Amended code - required price is first price from the top in column D - should always be cell D2
                
                cell.Offset(0, 1).Value = .Range("D2").Value
            End With
            
            DoEvents
        Next
        
    End With
    
End Sub


Private Function Create_Web_Query(wqSheet As Worksheet) As QueryTable

    Dim i As Integer
    
    'Delete all queries on web query sheet
    
    With wqSheet
        For i = .QueryTables.Count To 1 Step -1
            .QueryTables(i).Delete
        Next
        .Cells.ClearContents
    End With

    Set Create_Web_Query = wqSheet.QueryTables.Add(Connection:="URL;", Destination:=wqSheet.Range("A1"))
    
    With Create_Web_Query
        .Name = "sokker.org"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .WebSelectionType = xlAllTables
        .WebFormatting = xlWebFormattingNone
        .WebPreFormattedTextToColumns = True
        .WebConsecutiveDelimitersAsOne = True
        .WebSingleBlockTextImport = False
        .WebDisableDateRecognition = False
        .WebDisableRedirections = False
    End With
    
End Function
If you have any more related questions, please reply to this thread and not via PM, because many more people will see your question and may be able to help.
 
Upvote 0
It works, perfect!!! thank you.

You are probably the most helpful person what I met at least in last year.

Thanks, Regards Martin (Slovakia)
 
Upvote 0
Difficult to tell without the exact error message. One common problem is fixed by clearing the IE cache every few queries - search for code on this forum.
 
Upvote 0

Forum statistics

Threads
1,225,155
Messages
6,183,214
Members
453,151
Latest member
Lizamaison

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top