Enzo_Matrix
Board Regular
- Joined
- Jan 9, 2018
- Messages
- 113
I have a macro to log into my e-mail automatically which works perfectly if it is in its own workbook.
Once I transfer it to my personal workbook it generates an error each time I try to run it. "Compile error: User-defined type not defined" and highlights "HTMLDoc As HTMLDocument" in blue and the Sub name in yellow.
There is no difference in the code though and I cannot figure out how to resolve this. Please help.
Once I transfer it to my personal workbook it generates an error each time I try to run it. "Compile error: User-defined type not defined" and highlights "HTMLDoc As HTMLDocument" in blue and the Sub name in yellow.
There is no difference in the code though and I cannot figure out how to resolve this. Please help.
Code:
Sub Email()
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Dim Myhtml_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "https://www.abc.com/"
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.txtUSername.Value = "123"
HTMLDoc.all.txtPassword.Value = "123"
HTMLDoc.all.txtClient.Value = "company"
For Each Myhtml_Element In HTMLDoc.getElementsByTagName("Input")
If Myhtml_Element.Type = "Submit" Then Myhtml_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub