+ Reply to Thread
Results 1 to 23 of 23

Macro to download data from website (need fill in info and redirect to further pages)

  1. #1
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Macro to download data from website (need fill in info and redirect to further pages)

    Dear professionals

    I wish to write a macro, trying to do the following steps:

    1. open the website: http://webb-site.com/
    2. fill in a stock code (e.g 8120) AND click the button “current” redirect to another webpage
    3. Click the “raw prices”
    4. Import the data from web into the excel spreadsheet.


    1. open the website: http://webb-site.com/

    2. fill in a stock code (e.g 8120) AND click the button “current” redirect to another webpage
    1.jpg

    3. Click the “raw prices”
    2.png

    4. Import the data from web into the excel spreadsheet.
    1.jpg


    Many many thanks....

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Quote Originally Posted by tatfish87 View Post
    I wish to write a macro
    Hi,

    where is your code ?


    Automate Internet Explorer

  3. #3
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Sub createseed()
    '
    ' createseed 巨集
    '

    '
    With ActiveSheet.QueryTables.Add(Connection:= _
    "URL;http://webb-site.com/dbpub/hpu.asp?i=2972", Destination:=Range("$A$1"))
    .Name = "hpu.asp?i=2972"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .BackgroundQuery = True
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .WebSelectionType = xlSpecifiedTables
    .WebFormatting = xlWebFormattingNone
    .WebTables = "4"
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With
    End Sub


    I use the "record macro" function of excel to get the above code, but the problem i encounter is that, i have to manually do step 1 to step 3 to go to the page :http://webb-site.com/dbpub/hpu.asp?i=2972

    1. open the website: http://webb-site.com/
    2. fill in a stock code (e.g 8120) AND click the button “current” redirect to another webpage
    3. Click the “raw prices”

    Can it be some code for automate the step 1 to step 3 please? Many thanks...

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to download data from website (need fill in info and redirect to further pages)


    You must respect forum rules about code tags !


    You don't have to start from the home site as you should see in the webpage address after submit Current button …

    Follow samples in my previous post link to begin your code to pilot IE …


    4. Import the data from web into the excel spreadsheet.
    Which ? Where ? …

  5. #5
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Hi Marc, sorry for overlook, i am new comer.. will take note for the code tags in future..

    I wish to set up a button (with the macro inside) in an excel file, after pressing it, then create another new excel file and import the data into it...

    thank you..

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to download data from website (need fill in info and redirect to further pages)


    Quote Originally Posted by tatfish87 View Post
    import the data into it...
    Which data ?

  7. #7
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    I have study your previous post and revise the code as follow:

    Please Login or Register  to view this content.


    The macro work well until the following: I wish to automate the IE to click the text link "raw prices" of the first row (there are several text link named "raw prices" . Would you please kindly teach me to debug? I have replace the "Forgot your Password?" with "raw prices" but fail to work...thanks



    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    For further clarification, i wish to import all the data (after click into the text link "raw prices" ... into a newly create excel file.

    Which mean.. macro button on excel file A, use the macro to create excel file B with the imported data... Thanks..

    The code above is just doing the automate internet part, not yet reach the create excel file part, as i am being stucked at the step of automate clicking the text link "raw prices".

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Try this !


    Sometimes a code piloting IE works well on my side (Seven & IE9 or Windows 8 & IE10)
    but does not on other computers (Seven & IE10 for example) …
    Because in this case there is nothing to pilot,
    from a stock webpage just have to find out a sub webpage to grab it all,
    better and faster is to use request :

    Please Login or Register  to view this content.
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 11-28-2014 at 10:10 AM. Reason: optimization …

  10. #10
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    I must express my high appreciation and thank you to you.

    However, at the same time i have a little bit depress as i cannot continuing the code which i am using(which was done by many try and error as a newbie). Anyway really thank you.
    As this code is totally different thing, i cannot understand much.

    This macro works very nice to capture the whole page data into a new created excel (file name book1)
    May I have a little more about it please?

    I created a button(with your macro code inside) at Excel file A.
    Is it possible that, i enter the stock code (replace 8120) in a cell of Excel A, then run your macro, and then generate the Excel B (with file named "seed") ??
    Currently i need to manually replace the 8120 inside the code in order to retrieve the data for another stock..

    Lastly for this data capture, i dont need the capture all above the row of "Trade day, close, high low...."
    Anyway, i can use another macro to delete them, just see if it is possible to get rid of it from the beginning...

    Again, thank you for your time and expertise !! you are excellent.

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to download data from website (need fill in info and redirect to further pages)


    Thanks for the rep' !

    I asked you twice which data you need to import and you finally answered all data …
    It's why I choosed the clipboard way. Using object HTMLFile works like an IE document …

    • In fact you just need the table with dates and amounts ? Paste in new workbook starting in which cell ? B2 ?

    • For the stock code, you can amend line #6 by replacing the STOCK variable by the cell address …
    I don't know which cell from which worksheet from I suppose the workbook where is located the code.

    • The new workbook must be saved to be named but I don't know where ! In same path than workbook with code ?

    I can't guess anything, you must crystal clear explain !
    It's like from Victoria Peak you ask me to see a car in Kow Loon ! (sorry for the spell)
    Last edited by Marc L; 11-29-2014 at 01:35 AM.

  12. #12
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    - I wish to paste the data (table) at cell A1 , sheet2 of the new created excel file. Sorry for not making myself clear.

    - I wish to type the stock code in the cell G2 of excel A (original file contain the button & macro), is it i should replace the "STOCK" in line 6 of your code with "=G2"?

    - Can the macro instructed the newly created excel B to be saved at a desinated path? currently i wish to save it with name "seed" at the same directory of the workbook with macro (you are correct) ..

  13. #13
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    For the stock code part, i have tried this but not work..

    Please Login or Register  to view this content.
    i have amended line 1 and line 6..but not work..

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to download data from website (need fill in info and redirect to further pages)


    Your changes mean nothing but an error … For Excel VBA basics, use the Macro recorder, the newbie best friend !

    A VBA code must respect Excel objects levels : Application / Workbook / Worksheet / Cells …
    So cell G2 from workbook A : ok but don't you think something is missing ?

    I wrote clear for it in my previous post :

    I don't know which cell from which worksheet from I suppose the workbook where is located the code.
    For the new workbook, once saved, should be closed or stays opened ?

  15. #15
    Registered User
    Join Date
    11-29-2014
    Location
    mumbai
    MS-Off Ver
    XP
    Posts
    1

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Thanks it was of good help

  16. #16
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    Yes i always use macro recorder , but cant with your code, it seems different thing..

    The code should be located in Excel A.
    I want the button locate at sheet1 of Excel A.
    The Cell G2 on sheet1 of Excel A for me to enter a stock code (e.g 8120).

    After i enter the stock code in G2 on sheet1 of Excel A... press the button (contain your code).
    Generate a new excel file B, with the data pasted starting at cell A1 on sheet1 of excel B..

    It will be very kind for you to amend your original code for me this time.. so i can understand the core part of the amendment.. Thank you again Marc..

    For the new workbook (Excel B named "seed"). should be closed once saved. (in the same directory of excel A)

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    Modify a cell value is a very Excel basics, so using Macro Recorder brings VBA code to reach a cell
    whatever the kind of code (by the way several request samples in this forum !) …

    Please Login or Register  to view this content.

  18. #18
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    Thank you very much, it works nicely.. in my excel A.. there is a macro, will open the newly created (excel B) to get the data inside..the code is as follow:

    Please Login or Register  to view this content.
    Actually, "Processor" is my Excel A... putting at desktop. The "Seed" is Excel B, also at desktop
    When i run the above code, error occurs at the row of
    Please Login or Register  to view this content.
    I dont have such error if the seed is manually created by data import from web.. Do you know the reason of it?

    THank you again.

  19. #19
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    I believe the error is not caused by the file name. i have tried to rename the manually created excel B to "seed".. then the error does not occur.

    If the "seed" is created by using your code.. then the error will occur at
    Please Login or Register  to view this content.
    So i guess there is different in nature of the macro created "seed" and the manual created "seed"....

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: Macro to download data from website (need fill in info and redirect to further pages)


    Obviously, error cames from file name in your code not equal to real file name ‼
    Just see in Windows Explorer as in my code …


    Quote Originally Posted by tatfish87 View Post
    there is a macro, will open the newly created (excel B) to get the data inside
    If you need data in workbook A, why create workbook B ?‼ Why not loading data directly in workbook A ? …

  21. #21
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    I wish to create a new excel B because i wish my excel A is a processor only.

    I will alter the format of the downloaded data, so wish to have separate files (1 file for 1 stocks data)..
    also i wish to have the previous stock data saved (not lost the previous data every time when I analyse a new one).
    After Excel A got the data from Excel B, i will change the name of "seed" to "8120"..
    So that next time i can use yr code to generate a new "seed"... etc etc

    Which part for my code can be amended in order to tackle this problem? sorry please dont angry to me
    Last edited by tatfish87; 11-30-2014 at 08:43 AM.

  22. #22
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Macro to download data from website (need fill in info and redirect to further pages)


    So you just have to change file name in your code accordingly to file created as you must see in Windows Explorer
    or vice-versa, just modify file name in procedure creating file acordingly to your code, easy logic …
    Last edited by Marc L; 11-30-2014 at 12:28 PM.

  23. #23
    Registered User
    Join Date
    07-29-2014
    Location
    Hong Kong
    MS-Off Ver
    2010
    Posts
    34

    Re: Macro to download data from website (need fill in info and redirect to further pages)

    Dear Marc

    I have figured out the problem finally, there is a "space" after the name "seed"

    Thanks a lot for your time..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need to develop a macro to copy the data from multiple pages on same website
    By loveexcel2014 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2014, 05:33 PM
  2. Creating a macro to download data from a secure website
    By bakerbaz04 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2014, 01:38 PM
  3. How to download data from password protected website?
    By Excellearner2012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-21-2013, 08:40 PM
  4. Macro/VBA code for COLLECT DATA FROM VARIOUS PAGES OF ONE WEBSITE..
    By gunjan.nasit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-19-2013, 03:26 PM
  5. download info from website
    By sashun in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 10-22-2007, 10:42 AM

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