Macro from personal Workbook not working

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.
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
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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