L
luigimut
I have a quite complex issue that I am trying to solve (the Italian excel
newsgroup hasn’t give me any answer at the moment).
The goal is to create an excel macro written in VBA that should effect the
following: a) open a IExplorer window containing a form (username and
password) b) fill the form automatically with the given username and password
and submit the form.
The form is part of an SQL database running on the company server.
By looking for solutions on internet I found several solutions that work,
for instance on the Google search window.
One of them adapted and working is the following:
QUOTE
Sub FILLWEBFORMGOOGLE() ' IT WORKS ON GOOGLE!!!!!!!!!!!!!!
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim myIE As New InternetExplorer 'New '
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
'Set starting URL and search string
myURL = "http://google.com"
strSearch = "pippo"
'Make IE navigate to the URL and make browser visible
myIE.navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.document
'Enter search string on form
myDoc.forms(0).q.Value = strSearch
'Submit form
myDoc.f.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
MsgBox myIE.LocationName
End Sub
UNQUOTE
I tried then to apply the same scheme to my case but the macro doesn’t work.
The code used was the following
QUOTE
Sub FILLWEBFORM()
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim myIE As New InternetExplorer 'New '
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
'Set starting URL and search string
myURL = "http://ro-srv9/nostrogestionale/"
strSearch = "pippo"
'Make IE navigate to the URL and make browser visible
myIE.navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.document
'Enter search string on form
myDoc.forms(0).UserName.Value = strSearch
'Submit form
myDoc.contest.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
MsgBox myIE.LocationName
End Sub
UNQUOTE
The problem is probably due to the syntax to identify the form and the
element UserName in the HTML. The last one should be filled with the text
“pippoâ€. Probably the code
myDoc.forms(0).UserName.Value = strSearch
is wrong (it’s there where the macro is stuck)
I don’t know how to write this code in order to obtain the result. Can
anybody help me on this issue? Can You also suggest articles and literature
on this topic?
Thanks for Your cooperation (I add also the HTML code of the IExplorer
window containing the form that I have to fill, in case is useful)
<HTML>
<HEAD>
<TITLE>Login</TITLE>
<LINK REL="stylesheet" HREF="Library/Ccs/style.css">
<SCRIPT LANGUAGE="JavaScript" SRC="Help/HelpLib.js"></script>
<STYLE TYPE="text/css">
.titolo, .messaggio
{
font-family: Trebuchet Ms;
font-size: 10pt;
font-weight: bold;
text-align: right;
}
.messaggio
{
text-align: center;
color: #CC0000;
}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
function START()
{
var f = document.contest;
parent.alto.location.href = "Testata.asp";
}
</SCRIPT>
</HEAD>
<BODY onLoad="START()">
<DIV VALIGN="center" ALIGN="RIGHT">
<TABLE width=100% border=0 cellpadding=0 cellspacing=0>
<TR align=left>
<TD align=left valign=bottom width=100%>
<FONT class=SID_PageTitle>Sistema Gestionale societa’</FONT><BR>
<FONT class=SID_SubTitle>Procedura di Logon</FONT>
<HR>
</TD>
</TR>
<TR>
<TD>
<FORM NAME="contest" ACTION="Login.asp" METHOD="post">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="80%">
<TR>
<TD CLASS="titolo">UserName </TD>
<TD> <INPUT NAME="UserName" MAXLENGTH="50"></TD>
</TR>
<TR>
<TD CLASS="titolo">Password </TD>
<TD> <INPUT TYPE="password" NAME="password" MAXLENGTH="20"></TD>
</TR>
</TABLE>
<TABLE CLASS="CMD_Table" WIDTH=100%><TR>
<TD CLASS="CMD_TableCell" align="right">
<INPUT type=submit name=btnLogin CLASS="BTN_Comandi" value="ENTRA">
</TD>
</TR></TABLE>
</FORM>
</TD>
</TR>
</TABLE>
</DIV>
</BODY>
</HTML>
newsgroup hasn’t give me any answer at the moment).
The goal is to create an excel macro written in VBA that should effect the
following: a) open a IExplorer window containing a form (username and
password) b) fill the form automatically with the given username and password
and submit the form.
The form is part of an SQL database running on the company server.
By looking for solutions on internet I found several solutions that work,
for instance on the Google search window.
One of them adapted and working is the following:
QUOTE
Sub FILLWEBFORMGOOGLE() ' IT WORKS ON GOOGLE!!!!!!!!!!!!!!
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim myIE As New InternetExplorer 'New '
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
'Set starting URL and search string
myURL = "http://google.com"
strSearch = "pippo"
'Make IE navigate to the URL and make browser visible
myIE.navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.document
'Enter search string on form
myDoc.forms(0).q.Value = strSearch
'Submit form
myDoc.f.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
MsgBox myIE.LocationName
End Sub
UNQUOTE
I tried then to apply the same scheme to my case but the macro doesn’t work.
The code used was the following
QUOTE
Sub FILLWEBFORM()
'This project includes references to "Microsoft Internet Controls" and
'"Microsoft HTML Object Library"
'Variable declarations
Dim myIE As New InternetExplorer 'New '
Dim myURL As String
Dim myDoc As HTMLDocument
Dim strSearch As String
'Set starting URL and search string
myURL = "http://ro-srv9/nostrogestionale/"
strSearch = "pippo"
'Make IE navigate to the URL and make browser visible
myIE.navigate myURL
myIE.Visible = True
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
'Set IE document into object
Set myDoc = myIE.document
'Enter search string on form
myDoc.forms(0).UserName.Value = strSearch
'Submit form
myDoc.contest.submit
'Wait for the page to load
Do While myIE.Busy Or myIE.readyState <> READYSTATE_COMPLETE
DoEvents
Loop
MsgBox myIE.LocationName
End Sub
UNQUOTE
The problem is probably due to the syntax to identify the form and the
element UserName in the HTML. The last one should be filled with the text
“pippoâ€. Probably the code
myDoc.forms(0).UserName.Value = strSearch
is wrong (it’s there where the macro is stuck)
I don’t know how to write this code in order to obtain the result. Can
anybody help me on this issue? Can You also suggest articles and literature
on this topic?
Thanks for Your cooperation (I add also the HTML code of the IExplorer
window containing the form that I have to fill, in case is useful)
<HTML>
<HEAD>
<TITLE>Login</TITLE>
<LINK REL="stylesheet" HREF="Library/Ccs/style.css">
<SCRIPT LANGUAGE="JavaScript" SRC="Help/HelpLib.js"></script>
<STYLE TYPE="text/css">
.titolo, .messaggio
{
font-family: Trebuchet Ms;
font-size: 10pt;
font-weight: bold;
text-align: right;
}
.messaggio
{
text-align: center;
color: #CC0000;
}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
function START()
{
var f = document.contest;
parent.alto.location.href = "Testata.asp";
}
</SCRIPT>
</HEAD>
<BODY onLoad="START()">
<DIV VALIGN="center" ALIGN="RIGHT">
<TABLE width=100% border=0 cellpadding=0 cellspacing=0>
<TR align=left>
<TD align=left valign=bottom width=100%>
<FONT class=SID_PageTitle>Sistema Gestionale societa’</FONT><BR>
<FONT class=SID_SubTitle>Procedura di Logon</FONT>
<HR>
</TD>
</TR>
<TR>
<TD>
<FORM NAME="contest" ACTION="Login.asp" METHOD="post">
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="80%">
<TR>
<TD CLASS="titolo">UserName </TD>
<TD> <INPUT NAME="UserName" MAXLENGTH="50"></TD>
</TR>
<TR>
<TD CLASS="titolo">Password </TD>
<TD> <INPUT TYPE="password" NAME="password" MAXLENGTH="20"></TD>
</TR>
</TABLE>
<TABLE CLASS="CMD_Table" WIDTH=100%><TR>
<TD CLASS="CMD_TableCell" align="right">
<INPUT type=submit name=btnLogin CLASS="BTN_Comandi" value="ENTRA">
</TD>
</TR></TABLE>
</FORM>
</TD>
</TR>
</TABLE>
</DIV>
</BODY>
</HTML>