I am building a project and I understand that Excel 2003 supports the import of data from external webpages via “Data -> Import External Data -> New Web Query”.
This can be done via the few steps listed here: http://www.internet4classrooms.com/excel_import.htm
However, the site I am importing data from is an internal website (Intranet) and it requires a login everytime I access it.
The website does not remember the password and everytime I hit the “import” button, it does not do anything due to the login.
How do I prompt for a username + password and login to the website while importing the data from an external website in Excel 2003?
I ran into this about a year ago and as JimmyPena suggested, IE automation is probably the way to go. This is going to look much more complicated then you were expecting but believe me, I spent hours trying to find a simpler way and couldn’t find one.
Take some time to learn about HTML and the DOM object. It might seem like overkill for what you are doing but it will come in handy down the road if you want to get data from websites. Here’s a script to get you pointed in the right direction:
Double click on the button you just created and paste in the following code:
Change the URL to your website and modify the
getelementmethods to work with your webpageThe trickiest part for someone unfamiliar with HTML and the DOM (Document Object Model) will be finding the correct elements on the page.
A good trick is to use Internet Explorer’s Developer Tool. Open up your intranet page in IE and press F12. This will open the Developer Tool. Click on the arrow icon (the arrow points up and to the left) in the toolbar and switch back to your intranet page. Hover over the page and you will see blue boxes painted around each element. Hover over the username login and click on the input box. This will highlight the HTML in the source code.
From here you can identify the element id, name, tagname, and class if it has one. Do some research on
getelementbyID,getelementsbytagname, etc. or step through the code above to get a feel for how it works.One last note, if your intranet page has a form element, you will have to get the form object with the
getelementmethods above and submit it with.submit. If the page uses a button object, get the button element and use.click. Good luck!