Web Login >>> usern & pw >>> vba won't submit 'Login' of entry

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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
This other url shows up (see web code) if one hovers the mouse over the button labeled "Login". Than button when manually pressed submits the entered username and password, what I need the code to do.
I expect I need some sort of code that references this? When I try looking at that page source I get nothing. I expect the type='hidden' ?
Not sure if this helps?
TTom

 
Upvote 0
Simply submit the (first) form:
Code:
    HTMLdoc.forms(0).submit
    While MyBrowser.Busy Or MyBrowser.ReadyState <> READYSTATE_COMPLETE
        DoEvents
    Wend
Please use CODE tags.
 
Upvote 0
John,
So elegant and simple!

I obviously still have some additional reading to do on this area of coding.
I appreciate the help to get me going in the meantime...
Thanks!
 
Upvote 0

Forum statistics

Threads
1,215,467
Messages
6,124,985
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top