filling out online html
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Filling out online html forms using VB

Filling out online html forms using VB

resolvedResolved · High Priority · Version 2007

replyReply Wed 11 Jan 2012, 11:07Delegate Daniel said...

Daniel has attended:
Excel VBA Intro Intermediate course

Filling out online html forms using VB

Hi,

I want to call internet explorer and direct it to a website and to fill out an online form from pre-created excel strings and then to submit that form.

Is there a way of achieving this in excel? I've found that I can use the shell command to execute programs but that's as far as I've got.

Thanks,

Daniel

For upcoming training course dates see: Pricing & availability

replyReply Wed 11 Jan 2012, 20:48Trainer Anthony said...

RE: Filling out online html forms using VB

Hi Daniel, thanks for your query. That is technical possible using API calls and code to parse the HTML, identify the tags, simulate keystrokes etc, but it would be a real pain to code and success could not be guaranteed. You'd be better off investigating doing it in VBScript or Javascript.

However, websites these days are set up to stop you from using a "bot" to fill them out automatically. Think of how this might be used on an auction bid, for example...

Hope this helps,

Anthony

replyReply Tue 17 Jan 2012, 11:44Delegate Robert said...

RE: Filling out online html forms using VB

Hello, we have an excel spreadsheet that does pretty much what you are suggesting developing. I have posted some sample code for you to take a look at/play with to see if it suits your needs. Basically you use the Internet Explorer object in Excel (not sure what Add In is required) and then you just navigate to a chosen location.

From ie8 onwards then there are a lot of internet explorer page elements that are 'protected' from this type of automation (stopping you from firing off values to populate them automatically) and depending on how the webpage you want to manipulate has been developed (right click on it and view source) then this approach may not be possible at all - this only works on webpages that have been built up with distinct individual 'elements' and not a single javascript lump or window but for basic stuff then I think something along these lines should suffice...

Sub BlahBlahBlah

Dim ie As Internet Explorer
Dim elephant as object

Application.StatusBar = "Logging into webpage"

Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "" & Worksheets("Working").Range("URL1") & ""

Do Until ie.Busy = False
Loop

'Signs In
ie.Document.all("UserName").Value = "" & Worksheets("Working").Range("USERNAME") & ""

ie.Document.all("Password").Value = "" & Worksheets("Working").Range("PASSWORD") & ""

ie.Document.all("txtProduct").Value = 5

'presses login
For Each Elephant In ie.Document.all
If Elephant.className = "button" Then
If Elephant.nameProp = "btn_login.gif" Then
Elephant.Click
End If
End If
Next Elephant

Do Until ie.Busy = False
Loop

Application.StatusBar = "Tidying up..."

ie.Quit
Set ie = Nothing

End Sub

replyReply Fri 27 Jan 2012, 13:54Trainer Anthony said...

RE: Filling out online html forms using VB

Thanks Robert. As you point out that will only work with tagged HTML controls. One piece of advice: keep your code self-documenting. Naming object variables "elephant" makes it really difficult to know which object you are manipulating.

Hope this helps,

Anthony

Fri 3 Feb 2012: Automatically marked as resolved.

 

Please browse our web site to find out more about
excel microsoft training and other Microsoft training courses.

Excel tip:

Printing spreadsheets without opening them first

Here's a fast way of printing a spreadsheet from Windows Explorer/My Computer.

Go to the location where the spreadsheet is saved on your computer, then right-click on the icon next to the document and select Print from the menu.

The spreadsheet will automatically open, print and close itself.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard