Saturday 6 August 2011

Open a website via VBA

Sometimes you may want to obtain data from an online source and import it into a spreadsheet.  This is easy to do, using the following statement:

Workbooks.Open Filename:="URL"

This statement opens the website in a spreadsheet, meaning that you can then use the same VBA commands as on any spreadsheet.  For example, if you want to obtain a number from the website (for example a stockquote), you can reference the cell containing the number required.  In order to find out which cell you must reference in the code, you must first open the website in Excel (using the command above) and find the correct cell in the spreadsheet.  Once you have the correct cell reference, you can then automatically open the website in a spreadsheet, store the number in a variable, and then close the website/spreadsheet.  Close the website with this statement:

Windows("Website Title").Close savechanges:=False

Note that to determine the Website Title, you must again use the method of opening the website in a spreadsheet; then look at the "file name" (displayed in the Excel header bar at the very top of the window).

1 comment:

  1. I read Your Post and really its really Nice Article & Very Informative Post Otherwise if any One Want To Grow your Career in Advanced Excel So There are Some Top Best Training Center for excel & Advanced Excel institute

    Advanced excel course in Delhi
    Advanced excel course in Noida
    Advanced excel Training in Delhi
    Advanced excel Training in Noida

    ReplyDelete