Download data from web page
Try This.
Sub Net2Phone1() 'Credit to Joel
Dim objIE As Object
Dim strServAcct As String
Dim Password As Object
Set SumSht = Sheets("Sheet1")
RowCount = 2
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
Do While SumSht.Range("A" & RowCount) < ""
strServAcct = SumSht.Range("A" & RowCount)
objIE.Navigate "https://partner.net2phone.com/apps/account/search.aspx"
WaitForLoad objIE
Set UserId = objIE.document.getElementById("txtUserID")
If Not UserId Is Nothing Then
'Input user name and password
UserId.Value = "famaperu45"
Set Password = objIE.document.getElementById("txtPassword")
If Not Password Is Nothing Then
Password.Value = "my69car"
'submit the form by clicking "Login"
Set Login = objIE.document.getElementById("btnlogin")
Login.Click
WaitForLoad objIE
End If
End If
Set AccountBox = _
objIE.document.getElementById("ctl00$pageBody$txtS erviceAccount")
AccountBox.Value = strServAcct
Set SearchButton = _
objIE.document.getElementById("ctl00$pageBody$btnS earch")
SearchButton.Click
WaitForLoad objIE
'to get new account must navigate using control on page
Set CallHistoryNavigate = _
objIE.document.getElementById("ctl00_tvLeftNavn7")
CallHistoryNavigate.onclick = CallHistoryNavigate.href
CallHistoryNavigate.Click
WaitForLoad objIE
' in this web page are the "Cash Balance" and the "Total Cash Used"
Set CashBalance = _
objIE.document.getElementById("ctl00_pageBody_sctn TitleCtrl_lblTitle")
If Not CashBalance Is Nothing Then
'go back 2 tag tables
Set MyPoint = CashBalance
CountTables = 0
Do While CountTables < 2
Set MyPoint = MyPoint.ParentNode
If MyPoint.tagname = "TABLE" Then
CountTables = CountTables + 1
End If
Loop
SumSht.Range("B" & RowCount) = _
MyPoint.all(10).innertext
End If
Set TotalCash = _
objIE.document.getElementById("ctl00_pageBody_Labe l2")
If Not CashBalance Is Nothing Then
'go back 1 tag TR
Set MyPoint = TotalCash
CountTables = 0
Do While CountTables < 1
Set MyPoint = MyPoint.ParentNode
If MyPoint.tagname = "TR" Then
CountTables = CountTables + 1
End If
Loop
SumSht.Range("C" & RowCount) = _
MyPoint.all(5).innertext
End If
RowCount = RowCount + 1
Loop
objIE.Quit
Set objIE = Nothing
End Sub
Sub WaitForLoad(IE As Object)
Do While IE.Busy = True Or IE.readystate < 4
DoEvents
Loop
End Sub
"farid2001" wrote:
Dear Gentlemen
I need help for code to download for each strServAcct 2 items from web page
into cells in workbook. This 2 items are "Cash Balance" and "Total Cash Used"
This is how worksheet should look like:
Col A Col B Col C
strServAcct Cash Balance Total Cash Used
1190535741 xx.xx USd xx.xx USD
1615242148 xx.xx USd xx.xx USD
3484690293 xx.xx USd xx.xx USD
6689883508 xx.xx USd xx.xx USD
This is what I have so far:
Private Sub Workbook_Open()
Net2Phone1
End Sub
Sub Net2Phone1() 'Credit to Joel
Dim objIE As Object
Dim strServAcct As String
Dim Password As Object
strServAcct = "1190535741"
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "https://partner.net2phone.com/apps/account/search.aspx"
WaitForLoad objIE
Set UserId = objIE.document.getElementById("txtUserID")
If Not UserId Is Nothing Then
'Input user name and password
UserId.Value = "famaperu45"
Set Password = objIE.document.getElementById("txtPassword")
If Not Password Is Nothing Then
Password.Value = "my69car"
'submit the form by clicking "Login"
Set Login = objIE.document.getElementById("btnlogin")
Login.Click
WaitForLoad objIE
End If
End If
Set AccountBox = _
objIE.document.getElementById("ctl00$pageBody$txtS erviceAccount")
AccountBox.Value = strServAcct
Set SearchButton = _
objIE.document.getElementById("ctl00$pageBody$btnS earch")
SearchButton.Click
WaitForLoad objIE
objIE.Navigate "https://partner.net2phone.com/apps/account/calls.aspx"
WaitForLoad objIE
' in this web page are the "Cash Balance" and the "Total Cash Used"
End Sub
Sub WaitForLoad(IE As Object)
Do While IE.Busy = True Or IE.readystate < 4
DoEvents
Loop
End Sub
Your help will be greatly appreciated.
Thanks & regards
farid2001
|