2

I am trying to import the .csv from this URL:

http://www.redfin.com/stingray/do/gis-search?market=socal&region_id=11203&region_type=6&excl_ss=true&hoa=&max_listing_approx_size=&max_num_beds=&max_parcel_size=&max_price=300000&max_year_built=&min_listing_approx_size=&min_parcel_size=&min_price=50000&min_year_built=&num_baths=1.0&num_beds=1&open_house=&pkg=-&rd=&sf=1%2C2%2C3&sold_within_days=&status=1&time_on_market_range=30-&uipt=2&v=8&num_homes=500&sp=t&al=3&render=csv

The below code works when I use a different .csv URL, like this one: http://ichart.finance.yahoo.com/table.csv?s=AAPL&d=2&e=13&f=2013&g=d&a=8&b=7&c=1984&ignore=.csv

But the code does not work with the longer URL. Is the URL too long? If so, is there a workaround?

Here is my current code:

Sub importCSV()
    Dim URL As String
    URL = "TEXT;http://www.redfin.com/stingray/do/gis-search?market=socal&region_id=11203&region_type=6&excl_ss=true&hoa=&max_listing_approx_size=&max_num_beds=&max_parcel_size=&max_price=300000&max_year_built=&min_listing_approx_size=&min_parcel_size=&min_price=50000&min_year_built=&num_baths=1.0&num_beds=1&open_house=&pkg=-&rd=&sf=1%2C2%2C3&sold_within_days=&status=1&time_on_market_range=30-&uipt=2&v=8&num_homes=500&sp=t&al=3&render=csv"
    Application.DisplayAlerts = False
    With ActiveSheet.QueryTables.Add(Connection:=URL, _
        Destination:=Range("A1"))
        .Name = "test"
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlOverwriteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = 437
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = False
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
    Application.DisplayAlerts = True
End Sub

Matt

2
  • you can test if the URL is too short by using a URL shortener (goo.gl) try this shortened version if your long url: redfin.com. I've seen Excel freak out about some items that are longer than 255 characters (like a Range string input, for example). I wouldn't think they would limit this since URLs can be far longer than 255 characters Commented Mar 13, 2013 at 19:29
  • Also, what error are you getting with the long URL? Commented Mar 13, 2013 at 19:32

1 Answer 1

3

Try this:

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;[your url goes here]", Destination:=Range("$A$1"))
.Name = "home"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
End With

This works well for Excel 2010.

Sign up to request clarification or add additional context in comments.

4 Comments

I've tried your code and made these changes, using the long URL you've sent. It works fine for me.
This works great! Thank you. Is there a way to comma delimit, text-to-columns? It doesn't break the import into columns.
you can start the Macro recorder, and record the Text To Columns Excel's Data menu to get the code you need
Hi @user2113095! There is a way, yes, and I believe this is matter for another posting of you, what do you think about it? :-) You can also do as Philip says, however you'll lose the opportunity of trying it the hard way and learning a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.