filling out online html

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

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

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

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

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.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Conditional formatting for cells that return text , not picked up by Go to command

If you have tried to format all cells containing text even those that display text as a result of a formula you may have had difficulty. As Go to command with constant selected does not pick up formulas that result in text.

Then try this. Select the range the formula cells appear in on your sheet. Format, select Conditional Formatting menu. In the dialog box under Condition 1, select "Formula Is" from drop down. Next to it in the Formula Box, enter the formula =Istext(A1. Click Format button , choose desired formatting settings and click OK. To go ahead and apply the conditional formatting click OK to accept

View all Excel hints and tips


Server loaded in 0.07 secs.