+ Reply to Thread
Results 1 to 10 of 10

VBA Code for extracting data from Yahoo Finance

  1. #1
    Registered User
    Join Date
    04-11-2005
    Posts
    6

    Question VBA Code for extracting data from Yahoo Finance

    Can somebody help me with a VBA code for extracting data from Yahoo Finance?

    Thanks!

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    It would help if you posted the Url for the site

  3. #3
    Registered User
    Join Date
    04-11-2005
    Posts
    6

    url

    http://finance.yahoo.com/q/ae?s=


    or

    (for MSN Money) http://moneycentral.msn.com/investor...st.asp?Symbol=


  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    viorelmusca


    I went to Yahoo as per your URL, Made an equiry usinh yhoo as the symbol code
    After the data was displayed I copied the URL

    I then recorded this macro whilst I took the following actions

    Data Menu > Import External Data > New Web Query
    Paste URL into address
    Go Button
    Import button
    Follow the rest of the prompts

    You will need to change the yhoo code in the macro for what ever code you require

    Sub Macro2()

    With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://finance.yahoo.com/q?s=yhoo", Destination:=Range("A1"))
    .Name = "q?s=yhoo"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlOverwriteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = False
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With

    End Sub

  5. #5
    Registered User
    Join Date
    04-11-2005
    Posts
    6

    Exclamation

    Super! It's working..!! for yahoo ...

    i tryed this url:

    http://www.bvb.ro/cgi-bin/delayed/vi...elect_leng=ENG

    and is saying that there is no data ... (????)

    can you help me with this? or can you explain me why it isn't working ...??

    thanks!

    Viorel

  6. #6
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Viorel

    The URL appears to be incomplete.

    I am not sure if I found what you are after.

    This Url is for data found by folling the links under Monitering Tools > Delayed Info (Equuity Trade).


    Try replacing your Url with this one

    "URL;http://www.bvb.ro/cgi-bin/delayed/viewip.cgi?cmb=26368238636&select_leng=ENG&select_usercode=basic&select_usertype=basic&test=014258',5)"

    If this is not what you are after please post instructions how I get to the data page that you require.

  7. #7
    Registered User
    Join Date
    04-11-2005
    Posts
    6
    Yes, that' what I want.

    I used the url that you give me, but I get the same msg:

    "File cannot be opened because: a string literal was expacted, but no opening quote character was found. Line 6, Position 46" I don't know what this meens... Do you??

    .... Is there a chance to get that data???
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Viorel

    I don't know why you are having problems

    It works ok for me - I have wrapped the URL code incase that is causing the problem for you



    Sub Macro2()

    With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://www.bvb.ro/cgi-bin/delayed/viewip.cgi?cmb=" _
    & "26368238636&select_leng=ENG&select_usercode=" _
    & "basic&select_usertype=basic&test=014258',5)", _
    Destination:=Range("A1"))

    .Name = "q?s=yhoo"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlOverwriteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlEntirePage
    .WebFormatting = xlWebFormattingNone
    .WebPreFormattedTextToColumns = False
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With

    End Sub

  9. #9
    Registered User
    Join Date
    04-11-2005
    Posts
    6

    Arrow

    mudraker

    Do you have Office XP or 2003? I have Office XP. Do you think this may be the problem?

    I also used the macro you post, but it's giving me the same error msg.

    Can you please attach the worksheet?

    Thank you

    Viorel

  10. #10
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    I am using 2003

    I have attached a workbook that I created this morning by coping & pasting my code from my last reply and then running the macro.

    I do not know what the VBA code difference is between XP & 2003

    Have you tried recording a macro whilst you go through the steps of importing the data via a new web query


    then recorded this macro whilst I took the following actions

    Data Menu > Import External Data > New Web Query
    Paste URL into address
    Go Button
    Import button
    Follow the rest of the prompts

    Use the folling URL

    http://www.bvb.ro/cgi-bin/delayed/viewip.cgi?cmb=26368238636&select_leng=ENG&select_usercode=basic&select_usertype=basic&test=014258',5)

    Try the above steps then post your recorded code & I will look at it
    Attached Files Attached Files

+ 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