PDA

View Full Version : VBA to login in to website



jigar1276
01-08-2016, 12:11 AM
Hello,

I have written the VBA to open a website and login into it.


Option Explicit

Sub Login2Asite()

Dim appIE As InternetExplorerMedium

SetRefs
Set appIE = New InternetExplorerMedium
appIE.Visible = True
appIE.Navigate "https://www.asite.com/login-home/"
While appIE.Busy
DoEvents
Wend
With appIE.Document
.forms("frmlogin").elements("_58_login").Value = "myusername"
.forms(1).elements(1).Value = "mypwd"
.GetElementsByName("rbClaimsUse").Item(0).Click
End With

Set appIE = Nothing
End Sub

Sub SetRefs()
On Error Resume Next
' Adds Internet Controls Ref (SHDocVw.dll)
ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End Sub


The code is opening the website but giving error "Object Variable or block variable not set". once the code enters into "With appIE.Document" loop.
I am new to do auto things with IE so not knowing much about forms and elements. Please let me know how I can get exact form and element names from webpage.

Thanks,
Jigar