F
fi.or.jp.de
Hi all,
I have web interactive macro, which logs into the web.
It click serach button and result will be populated in excel but
I got one small problem here if there is no search result it will
pop window saying "no results found", then I have to click OK button
to continue the macro.
how should click ok automatically.
Please help me.
Here's the code i have used ( URL is internal )
Option Explicit
Function web_test ()
Dim ie As InternetExplorer
Dim URL As String
Dim Entid As Object, pwd As Object, form As Object
Dim pwd1 As Object, form1 As Object
Dim Fname As Object
Dim Acn As String, Acs As String
Dim Srch As Object
Dim status As Object, gender As Object, org As Object
Dim clr As Object
Dim I As Integer, Rng As Integer
Dim CID As String
Dim form2 As Object
Acn = ActiveWorkbook.Name
Acs = ActiveSheet.Name
Set ie = CreateObject("internetexplorer.application")
URL = "https://xyz.aspx "
ie.Visible = True
ie.Navigate URL
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Set Entid = ie.Document.getelementsbyname("txtPersonnelNumber")
Set pwd = ie.Document.getelementsbyname("txtPassword")
Set form = ie.Document.getelementbyid("btnLogIn")
Entid.Item(0).Value = "fiorjpde"
pwd.Item(0).Value = "********"
form.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Rng = Workbooks(Acn).Sheets(Acs).Cells(Rows.Count, "A").End(xlUp).Row
For I = 2 To Rng
CID = Trim(Cells(I, "A").Value)
Set Fname = ie.Document.getelementsbyname("txtCID")
Fname.Item(0).Value = CID
Set Srch = ie.Document.getelementbyid("btnSearch")
Srch.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Set status =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lbldtgSta
tus")
Cells(I, "B").Value = status.innertext
Set gender =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lblGender")
Cells(I, "C").Value = gender.innertext
Set org =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lbldtgPre
vOrg")
Cells(I, "d").Value = org.innertext
Set clr = ie.Document.getelementbyid("btnClear")
clr.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Next I
End Function
I have web interactive macro, which logs into the web.
It click serach button and result will be populated in excel but
I got one small problem here if there is no search result it will
pop window saying "no results found", then I have to click OK button
to continue the macro.
how should click ok automatically.
Please help me.
Here's the code i have used ( URL is internal )
Option Explicit
Function web_test ()
Dim ie As InternetExplorer
Dim URL As String
Dim Entid As Object, pwd As Object, form As Object
Dim pwd1 As Object, form1 As Object
Dim Fname As Object
Dim Acn As String, Acs As String
Dim Srch As Object
Dim status As Object, gender As Object, org As Object
Dim clr As Object
Dim I As Integer, Rng As Integer
Dim CID As String
Dim form2 As Object
Acn = ActiveWorkbook.Name
Acs = ActiveSheet.Name
Set ie = CreateObject("internetexplorer.application")
URL = "https://xyz.aspx "
ie.Visible = True
ie.Navigate URL
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Set Entid = ie.Document.getelementsbyname("txtPersonnelNumber")
Set pwd = ie.Document.getelementsbyname("txtPassword")
Set form = ie.Document.getelementbyid("btnLogIn")
Entid.Item(0).Value = "fiorjpde"
pwd.Item(0).Value = "********"
form.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Rng = Workbooks(Acn).Sheets(Acs).Cells(Rows.Count, "A").End(xlUp).Row
For I = 2 To Rng
CID = Trim(Cells(I, "A").Value)
Set Fname = ie.Document.getelementsbyname("txtCID")
Fname.Item(0).Value = CID
Set Srch = ie.Document.getelementbyid("btnSearch")
Srch.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Set status =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lbldtgSta
tus")
Cells(I, "B").Value = status.innertext
Set gender =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lblGender")
Cells(I, "C").Value = gender.innertext
Set org =
ie.Document.getelementbyid("dtgCandidateDefaultSearchResult_ctl03_lbldtgPre
vOrg")
Cells(I, "d").Value = org.innertext
Set clr = ie.Document.getelementbyid("btnClear")
clr.Click
Do While ie.ReadyState <> 4 Or ie.Busy = True
DoEvents
Loop
Next I
End Function