mrmmickle1
Well-known Member
- Joined
- May 11, 2012
- Messages
- 2,461
I have the below code:
Which I am trying to modify to fit my needs:
I get the error User Defined type not defined on line:
Do I need to use references? Is there a quick fix for this?
I have code that works for a particular website but I am having trouble making it work for others. This code seems more flexible than the other code I have that Norie helped me with:
My end goal is to log on to several websites and pull data out of tables on the websites back into excel so that I can have a one stop shop instead of logging into many websites manually. Any Help would be appreciated.
Which I am trying to modify to fit my needs:
Rich (BB code):
Sub Test()
Const cURL = "Website Here" 'Enter the web address here
Const cUsername = "XXXXXX" 'Enter your user name here
Const cPassword = "XXXXXX" 'Enter your Password here
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
Dim UserNameInputBox As HTMLInputElement
Dim PasswordInputBox As HTMLInputElement
Dim SignInButton As HTMLInputButtonElement
Dim HTMLelement As IHTMLElement
Dim qt As QueryTable
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
'Wait for initial page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Set doc = IE.Document
'Get the only form on the page
Set LoginForm = doc.forms(0)
Set UserNameInputBox = LoginForm.elements("userid")
UserNameInputBox.Value = cUsername
Set PasswordInputBox = LoginForm.elements("password")
PasswordInputBox.Value = cPassword
Set SignInButton = LoginForm.elements("btnSignon")
SignInButton.Click
'Wait for the new page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
End Sub
I get the error User Defined type not defined on line:
Rich (BB code):
Dim IE As InternetExplorer
Do I need to use references? Is there a quick fix for this?
I have code that works for a particular website but I am having trouble making it work for others. This code seems more flexible than the other code I have that Norie helped me with:
Rich (BB code):
Option Explicit
Public Sub Press_Button()
'make sure you add references to Microsoft Internet Controls (shdocvw.dll) and
'Microsoft HTML object Library.
'Code will NOT run otherwise.
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Set objIE = New SHDocVw.InternetExplorer
With objIE
.Navigate "https://www.wellsfargo.com/" ' Main page
.Visible = 1
Do While .READYSTATE <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:02"))
'set user name and password
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("INPUT")
Do While htmlDoc.READYSTATE <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If htmlInput.Name = "userid" Then
htmlInput.Value = "Username Here"
Else
If htmlInput.Name = "password" Then
htmlInput.Value = "Password Here"
End If
End If
Next htmlInput
'click login
Set htmlDoc = .document
Set htmlColl = htmlDoc.getElementsByTagName("input")
Do While htmlDoc.READYSTATE <> "complete": DoEvents: Loop
For Each htmlInput In htmlColl
If Trim(htmlInput.Type) = "submit" Then ' This is the button name I need. Submit clicks a different button that directs me to the wrong page
htmlDoc.forms(1).submit
Exit For
End If
Next htmlInput
End With
End Sub
My end goal is to log on to several websites and pull data out of tables on the websites back into excel so that I can have a one stop shop instead of logging into many websites manually. Any Help would be appreciated.
Last edited: