Im a fresher to Excel Macros (VBA) and looking for a way to automate IE to login to a website and proceed to a certain page. website URL : https://www.mast-technicalservices.com/ecp/index2.jsp and need to fill the login details and click continue.
Sub WebsiteLogIn()
Dim nURL As String
Dim UNElementID As String
Dim UserName As String
Dim PWElementID As String
Dim Password As String
Dim SIElementID As String
Set LoginData = ThisWorkbook.Sheets("Sheet1")
Set nURL = "https://www.mast-technicalservices.com/ecp/index2.jsp"
Set UNElementID = "ecp_param_userId"
Set UserName = LoginData.Cells(1, "B").Value
Set PWElementID = "ecp_param_password"
Set Password = LoginData.Cells(2, "B").Value
Set SIElementID = "imageField2"
Dim IE As Object
Dim IEPage As Object
Dim IEPageElement As Object
'Create a new Internet Explorer instance, make it visible and maximize its window and navigate to url.
On Error Resume Next
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
ShowWindow IE.hwnd, SW_MAXIMIZE
IE.navigate URL
Set IEPage = IE.document
'setthe UserName text box using the element ID.
Set IEPageElement = IEPage.getElementById(UNElementID)
'set the Password text box using the element ID.
Set IEPageElement = IEPage.getElementById(PWElementID)
'set the Continue button using the element ID.
Set IEPageElement = IEPage.getElementById(SIElementID)
End Sub
This works:
The other sub:
ieBusy
will ensure the webpage is fully loaded prior to you attempting to manipulate it.