Here is a way, where after the information has been entered in to the form, at the push of a CommandButton it autmatically takes that information and sends it through the process at the Webpage.
This sample code sends Text from TextBox1 and TextBox2 to the test posting page on MrExcel.com.
To use this code for other web site, you need a little knowledge about HTML.
Click 'View Source' on the target web page, then find the name of the objects. Normally the objects are located between <form> to </form> tags.
For example, here is the part of the html source
of the MrExcel testing page
As you can see, this TextField object has a name "subject
". So you can access to this object with thes name
<input type="text" name="subject" size="45" maxlength="60" style="width:450px" tabindex="2" class="post"
value="" onkeydown="typeQuietly(this, event);" />
In some case, the objects in html code may not have the name. To access to the object, you can use index
, but you need to know about the structure of Html.
You can see .Subject.Value = sSbjct
in the code line of the sample VBA, it also can be written as follows.
.Document.forms(0).Item(0).Value = sSbjct
Since the index number starts from 0, it means inputting value to the First object of the First form in the Document object.
Place following in the Userform module.
Private Sub CommandButton1_Click()
Call TestPosting(TextBox1.Text, TextBox2.Text)
Private Sub TestPosting(sSbjct As String, sMsg As String)
Const url As String = _
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
.Visible = True
Do While .ReadyState <> 4: Loop
'//Send data to IE
.Subject.Value = sSbjct
.Message.Value = sMsg
Do While ie.ReadyState <> 4: Loop
Set ie = Nothing
MsgBox "Your text has been sent to the Test posting site."