ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA to click 'submit' on form (https://www.excelbanter.com/excel-programming/342626-excel-vba-click-submit-form.html)

nixter

Excel VBA to click 'submit' on form
 
I am scripting the input to an intranet website and am getting stuck at the
clicking submit button - despite trrying code samples from other posts and
boards...

essentially I am taking the value in cell A1, defining it as "base_url", and
navigating to that page. The script pulls in the IE page, waits for the load,
the password is entered successfully, and there's where it all ends where I
am trying to have a 'submit' event happen to the submit button. The button is
not named and everything runs fine up to the point of button click. Password
values pass thru no problem as when I manually click the button it navigates
to the next page...

I have tried, among other things in the code below:
..submit
..click

Sendkeys sequences
End With
..Visible = True
SendKeys "{TAB}", True
SendKeys "~", True


The text in the code:

input type=text name='orderID' value='370732'

is passed from the server upon URL navigation...
Still nothing. I am racking my brain - there's no reason I can think of for
this not to work. The "Click Submit" bolded below is where it hangs...

Thanks MUCH!

Coding below



code from the server:
--------------------------------------------------------------------------------
<FORM ACTION='' method='POST'
<table<tr
<td<bEnter The Server Password: </b</td
<td align=left<input type='password' name='password'</td</tr
<tr
<td<bEnter The Filename</b</td
<td align=left<input type=text name='orderID' value='370732'</td</tr
<tr<td</td<td align=center<input type='Submit' value='Submit'
</td</tr</table
</FORM
</body
</html
--------------------------------------------------------------------------------


--- VB Script ---

Sub process_item()

Sheets("input").Select

base_url = Cells(1, 1).Value


Range("A1").Select

Dim url As String

url = base_url

Dim ie As Object
'Dim document As Object
Set ie = CreateObject("internetexplorer.application")
With ie
..Visible = True
..Navigate base_url
Do While .ReadyState < 4
DoEvents
Loop

With .document.all
..Password.Value = "password123"
(This is where I hang up)
-- CLICK SUBMIT <--



Jake Marx[_3_]

Excel VBA to click 'submit' on form
 
Hi Nixter,

Instead of navigating to the URL, filling in form values, and then
attempting to submit the form or click a button, you may want to try the
XMLHTTP object. Here's a link to an example:

http://groups.google.com/group/micro...829784b4ad0c6b

With this method you are directly posting data to the URL specified in the
action attribute of the form element (in this case, it's blank, which means
it posts to itself). You may have to modify the form on the server to
include id or name attributes for the input elements, as that's how you can
refer to them when posting.

If you want to continue down the same path, you could name the form element,
then use something like this in your code:

.Document.GetElementById("myform").Submit

--
Regards,

Jake Marx
www.longhead.com


[please keep replies in the newsgroup - email address unmonitored]


Nixter wrote:
I am scripting the input to an intranet website and am getting stuck
at the clicking submit button - despite trrying code samples from
other posts and boards...

essentially I am taking the value in cell A1, defining it as
"base_url", and navigating to that page. The script pulls in the IE
page, waits for the load, the password is entered successfully, and
there's where it all ends where I am trying to have a 'submit' event
happen to the submit button. The button is not named and everything
runs fine up to the point of button click. Password values pass thru
no problem as when I manually click the button it navigates to the
next page...

I have tried, among other things in the code below:
.submit
.click

Sendkeys sequences
End With
.Visible = True
SendKeys "{TAB}", True
SendKeys "~", True


The text in the code:

input type=text name='orderID' value='370732'

is passed from the server upon URL navigation...
Still nothing. I am racking my brain - there's no reason I can think
of for this not to work. The "Click Submit" bolded below is where it
hangs...

Thanks MUCH!

Coding below



code from the server:
--------------------------------------------------------------------------------
<FORM ACTION='' method='POST'
<table<tr
<td<bEnter The Server Password: </b</td
<td align=left<input type='password' name='password'</td</tr
<tr
<td<bEnter The Filename</b</td
<td align=left<input type=text name='orderID'
value='370732'</td</tr <tr<td</td<td align=center<input
type='Submit' value='Submit' </td</tr</table
</FORM
</body
</html
--------------------------------------------------------------------------------


--- VB Script ---

Sub process_item()

Sheets("input").Select

base_url = Cells(1, 1).Value


Range("A1").Select

Dim url As String

url = base_url

Dim ie As Object
'Dim document As Object
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.Navigate base_url
Do While .ReadyState < 4
DoEvents
Loop

With .document.all
.Password.Value = "password123"
(This is where I hang up)
-- CLICK SUBMIT <--





All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com