TTom
Well-known Member
- Joined
- Jan 19, 2005
- Messages
- 518
I am writing a vba routine that requires a web page login before continuing.
I have the entry of username and password working but I can not get the submit event to occur.
I have researched and attempted a multiple of methods on this board and others without success.
I am using Windows XP and Excel 2003.
I do have my Excel Microsoft References: 'Microsoft Internet Controls' and ' Microsoft HTLM Object Library' in place.
Most code I've tried is coming back with an 'object error', so something is wrong in my assignment/use?
I am a bit confused by web code's 1st line with a different url than page I am on: 'action="new url aspx path" I don't know if I need this in my code, and if yes, how?
I am still a newbie in this code area, so still on learning curve on terminology and application.
1. THE LOGIN URL:
"http://www.dowtheory.com/subscriberarea/authentication/getpass.asp"
2. THE RELEVANT WEB PAGE CODE
NOTE: I removed web code's < > brackets so would display here as as text. I used separate line for each < > bracket set
<code>
form id="login" name="form1" action="http://secure.horizonpublishing.com/security/SQLLogon.aspx" method="POST"
Username:
label for="username"
/label
input id="username" type="text" name="Login"
/input
Password:
label for="password"
/label
input id="password" type="password" name="Password"
/input
input id="Pub" type="hidden" value="DTF" name="Pub"
/input
/form
</code>
3. MY VBA LOGIN CODE See comment area "I need help here.."
<code>
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim ieApp As InternetExplorer
Dim IeDoc As Object
'On Error GoTo Err_Clear
MyURL = "http://www.dowtheory.com/subscriberarea/authentication/getpass.asp"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.username.Value = "myusername" 'code enters my username here
HTMLDoc.all.password.Value = "mypassword" 'code enters my password here
'***My Code works this far****
'
'***I NEED HELP HERE***
'Need to trigger the 'Login Button' to submit above entries, can't find proper code!
'See the web code for relevant details
'
'****CONTINUING AFTER SUCCESSFUL LOGIN***
'My current code opens 'new page' instead of redirects from login page.
'Need to fix this next after I get login working...
MyURL = "http://www.dowtheory.com/subscriberarea/focus_list.asp"
Set MyBrowser = New InternetExplorer 'Ah, is using "new" the problem here?
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
'My remaining code to fetch table data goes here...
</code>
I always want to learn, but honestly some straight forward code help would be
a relief after research with many unsuccessful attempts! Then happy to read up.
Thanks, TTom
I have the entry of username and password working but I can not get the submit event to occur.
I have researched and attempted a multiple of methods on this board and others without success.
I am using Windows XP and Excel 2003.
I do have my Excel Microsoft References: 'Microsoft Internet Controls' and ' Microsoft HTLM Object Library' in place.
Most code I've tried is coming back with an 'object error', so something is wrong in my assignment/use?
I am a bit confused by web code's 1st line with a different url than page I am on: 'action="new url aspx path" I don't know if I need this in my code, and if yes, how?
I am still a newbie in this code area, so still on learning curve on terminology and application.
1. THE LOGIN URL:
"http://www.dowtheory.com/subscriberarea/authentication/getpass.asp"
2. THE RELEVANT WEB PAGE CODE
NOTE: I removed web code's < > brackets so would display here as as text. I used separate line for each < > bracket set
<code>
form id="login" name="form1" action="http://secure.horizonpublishing.com/security/SQLLogon.aspx" method="POST"
Username:
label for="username"
/label
input id="username" type="text" name="Login"
/input
Password:
label for="password"
/label
input id="password" type="password" name="Password"
/input
input id="Pub" type="hidden" value="DTF" name="Pub"
/input
/form
</code>
3. MY VBA LOGIN CODE See comment area "I need help here.."
<code>
Dim MyBrowser As InternetExplorer
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim ieApp As InternetExplorer
Dim IeDoc As Object
'On Error GoTo Err_Clear
MyURL = "http://www.dowtheory.com/subscriberarea/authentication/getpass.asp"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
HTMLDoc.all.username.Value = "myusername" 'code enters my username here
HTMLDoc.all.password.Value = "mypassword" 'code enters my password here
'***My Code works this far****
'
'***I NEED HELP HERE***
'Need to trigger the 'Login Button' to submit above entries, can't find proper code!
'See the web code for relevant details
'
'****CONTINUING AFTER SUCCESSFUL LOGIN***
'My current code opens 'new page' instead of redirects from login page.
'Need to fix this next after I get login working...
MyURL = "http://www.dowtheory.com/subscriberarea/focus_list.asp"
Set MyBrowser = New InternetExplorer 'Ah, is using "new" the problem here?
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Loop Until MyBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.Document
'My remaining code to fetch table data goes here...
</code>
I always want to learn, but honestly some straight forward code help would be
a relief after research with many unsuccessful attempts! Then happy to read up.
Thanks, TTom