Webpage login not working Using excel VBA - html

I am working on project to download the dump from website and save it on the path specified using Excel vba.
Code is working perfectly when u do the debug or execute line by line by pressing "F8".
but when you execute the whole program by pressing "F5" or clicking on button after assigning macro to it. its not working.
need your precious advise to resolve this issue.
Thanks in Advance,
Prasanna
VBA Code used to login.
Sub Login()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
MyURL = "URL"
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.Navigate MyURL
MyBrowser.Visible = True
Do
Application.Wait DateAdd("s", 5, Now)
Loop Until MyBrowser.READYSTATE = READYSTATE_COMPLETE
Application.Wait DateAdd("s", 5, Now)
Set HTMLDoc = MyBrowser.document
HTMLDoc.all.Country_Code.Value = "Country_Code"
HTMLDoc.all.Login.Value = "UserName"
HTMLDoc.all.passwd.Value = "Password"
HTMLDoc.all.Item("B1").Click
For Each MyHTML_Element In HTMLDoc.getElementsByName("B1")
If MyHTML_Element.Type = "button" Then MyHTML_Element.Click: Exit For
Next
End sub
Sample HTML code of webpage for login.
<table border=0>
<tr>
<td>Country:</td>
<td>
<input type="text" name="country_code" maxlength=2
onblur="this.value=this.value.toUpperCase();Form1_action(this.value)">
</td>
</tr>
<tr>
<td>Language:</td>
<td>
<select name="idioma" disabled >
<option value="uk|es" onblur="document.Form1.login.focus()">ENGLISH</option>
<option value="sp|es" onblur="document.Form1.login.focus()">SPANISH</option>
<option value="fr|en-us" onblur="document.Form1.login.focus()">FRENCH</option>
<option value="it|en-us" onblur="document.Form1.login.focus()">ITALIAN</option>
<option value="de|de" onblur="document.Form1.login.focus()">GERMAN</option>
</select>
</td>
</tr>
<tr>
<td>Login:</td>
<td>
<input type="text" name="login" maxlength=10 value="" disabled >
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input type="password" autocomplete="off" name="passwd" maxlength=10 value="" disabled onkeypress="var okp=(event.which)?event.which:event.keyCode; if(okp==13) SiteRedirect(this.form)">
</td>
</tr>
</table>
<br>
<center>
<input type="button" name="B1" value="Sign In"
onclick="SiteRedirect()"
disabled
style="width:80pt"
>
</center>

This is the method I use to allow IE to load in an application that frequently works with webpages in IE. I have come to this after a lot of trial and error and it works consistently now - though I have seen many ways to accomplish this.
Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As LongPtr)
Sub IEWait(IE As Object)
'assumes IE is loaded as InternetExplorer.Application")
With IE
Do While .Busy Or .ReadyState <> 4: Sleep (100): Loop
End With
End Sub
You can add this to your code by
Placing the Public Declare at the top of your module window before any Sub are defined.
Incorporating it into your code as shown below.
Code:
With MyBrowser
.Silent = True
.Navigate MyURL
.Visible = True
Do While .Busy or .Readystate <> 4: Sleep (100): Loop
Set HTMLDoc = .document
'... rest of code
End With

Scott hit the nail on the head.
Sub Test()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "http://www.marketwatch.com/investing/stock/aapl/analystestimates" ' should work for any URL
Do Until .ReadyState = 4: DoEvents: Loop
. . . YOUR CODE HERE . . .
End With
End Sub
OR
Sub DumpData()
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "http://finance.yahoo.com/q?s=sbux&ql=1"
'Wait for site to fully load
IE.Navigate2 URL
Do While IE.Busy = True
DoEvents
Loop
. . . YOUR CODE HERE . . .
End Sub

Related

Hidden Button Click in HTML through VBA

<tr>
**<td>**JB - Al Qouz**</td>**
**<td>**
<strong>0</strong>
<input type="hidden" name="ingredient[inventories_attributes][][id]" id="ingredient_inventories_attributes__id" value="5564069">
<small><span class="buyUnitValueText ">pc</span></small>
<small><b><span id="totalStockValue_1" class="hide paddingLeft15 updateTotalStockValue"></span></b></small>
**</td>**
**<td>**
<div class="align-left">
<input type="text" name="ingredient[inventories_attributes][][reorder_level]" id="ingredient_inventories_attributes__reorder_level" value="0" class="span5 menuItemInventory reOrderValue">
<small><span class="buyUnitValueText span7 labelText pull-right align-left">pc</span>
</small>
</div>
**</td>**
<td class="align-left">
<input type="hidden" name="ingredient[inventories_attributes][][track_inventory]" id="track_inventory_9971" **value="true"**>
**<div class="vCheckBox trackInventoryCheckbox active" id="9971"></div>**
I need to change 2 things (See Bold) if "id=9971" through vba.
Set class vCheckBox trackInventoryCheckbox active to class vCheckBox trackInventoryCheckbox
Set value="true" to value="false"
Reason being, I'm not able to click the button through VBA and the code change in html that occurs when I click manually are the 1. & 2. mentioned above.
Please advise, below is my code where I tried to get tag value through tr but couldn't, second part was where I could change the values.
With ie
.Visible = True
.navigate (EditIngredientURL)
While .Busy Or .readyState <> 4: DoEvents: Wend
While .document.readyState <> "complete": DoEvents: Wend
End With
Set HTMLdoc = ie.document
Set tr = HTMLdoc.getElementsByTagName("tr")
For Each trObj In tr
Set td = trObj.getElementsByTagName("td")
For Each tdObj In td
If InStr(tdObj.innerText, "JB - Al Qouz") Then
Debug.Print tdObj.innerText
Set CheckBox = tdObj.getElementsByTagName("class")
For Each idnumber In CheckBox
Debug.Print idnumber.innerText
Exit For
Next
End If
Next
Next
End Sub
If the ID is known and you have it in a variable idNo you can use it to locate the elements:
idNo = "9971"
HTMLdoc.getElementById("track_inventory_" & idNo).value = "false"
HTMLdoc.getElementById(idNo).className = "vCheckBox trackInventoryCheckbox"

Click on Checkbox in Website using Excel VBA

There is a website that has some data I want for my work. I login check some checkbox and submit, then the website will send me an email with my data. But it takes way too long to receive my information so I want to automate it so everyday first hour in the morning the information is requested, like that I will already have it on my email when I need it.
I modified some code and I already managed to login and go to the page where I need to click the checkbox (there are three of them) and then click on a submit button.
Sub GetTable()
Dim ieApp As InternetExplorer
Dim ieDoc As Object
Dim ieTable As Object
Dim chkBox As Object
'create a new instance of ie
Set ieApp = New InternetExplorer
'you don’t need this, but it’s good for debugging
ieApp.Visible = True
'assume we’re not logged in and just go directly to the login page
ieApp.Navigate "http://mydata/aspx/mydataLogon.aspx?Language=2"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
'fill in the login form – View Source from your browser to get the control names
With ieDoc.forms(0)
.txtUsername.Value = "usertest"
.txtPassword.Value = "test123"
.Submit
End With
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
'now that we’re in, go to the page we want
ieApp.Navigate "http://mydata/InventoryTracking/aspx/rptDefault.aspx?rpt=../aspx/invRptDetailReport.aspx"
Set ieDoc = ieApp.Document
With ieDoc
'I tried with getElementbyId, I dont get any error but the chkbox still comes as with a nothing value
Set chkBox = ieDoc.getElementByid("cblPlants_0")
'therefore these give error too, I dont know why. A an object variable or with block variable not set error
chkBox.Click
chkBox.Checked = True
'here I get an object variable or with block variable not set error
ieDoc.getElementByid("cblPlants_0").Click
.Submit
End With
End sub
The checkbox control I want is inside of this:
'first there is a form and this is how the iframe is first called I think
<form name="_ctl1" method="post" action="rptDefault.aspx" id="_ctl1">
<table width="100%" HEIGHT="100%" cellpadding="0" cellspacing="0" border="0">
<TR>
<TD CLASS="Normal" COLSPAN="4"><IFRAME ID="IFRAME1" NAME="IFRAME1" SRC="../aspx/invRptDetailReport.aspx" frameborder="0" width="100%" height="100%"></IFRAME></TD>
</TR>
'Now the iframe1 goes like this
<form name="frmRptDetailReport" method="POST" action="invRptDetailReport.aspx" id="frmRptDetailReport">
<table id="htblMainBody" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#E5DBE2">
<tr><td <a id="lbtnSelect" href="javascript:__doPostBack('lbtnSelect','')"</a>
<div id="divChkboxlist" class="scrollingControlContainer scrollingCheckBoxList" onscroll="saveScrollPos();">
<table id="cblPlants" border="0" style="font-family:Arial;font-size:11px;width:275px;overflow: scroll"><tr>
<tr><td><input id="cblPlants_0" type="checkbox" name="cblPlants:0" onclick="javascript:setTimeout('__doPostBack(\'cblPlants$0\',\'\')', 0)" language="javascript" /><label for="cblPlants_0">1X1 -Confecciones</label></td>
</tr>
How can I check this check box on this page? After the checkbox is checked I will receive the email I want.
If you need more information please tell me
Try
ieDoc.querySelector("#cblPlants_0").click
Equivalent to:
ieDoc.getElementById("cblPlants_0").click
Remember to have proper page load waits after the .Navigate step before attempting the click
While ieApp.Busy Or ieApp.readyState < 4: DoEvents: Wend
Set ieDoc = ieApp.Document
ieDoc.getElementById("cblPlants_0").click
You may need an additional wait before the click. Step through with F8 to test.
You could also try executing the javascript
ieDoc.parentWindow.execScript "javascript:setTimeout('__doPostBack(\'cblPlants$0\',\'\')', 0)"

Cannot login to website using a macro and vba

I am trying to login to a website using the following which works on different url
Sub Mylogin()
Dim MyHTML_Element As IHTMLElement
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "MYURL"
ie.Silent = True
ie.Navigate MyURL
ie.Visible = True
Do
Loop Until ie.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc1 = ie.Document
HTMLDoc1.all.Email.Value = "MYEMAIL" 'Enter your email id here
HTMLDoc1.all.Password.Value = "MYPASSWD" 'Enter your password here
For Each MyHTML_Element In HTMLDoc1.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
The submit button is under div and I dont know if this is the problem. The html login part is the following
<div id="login-area-main">
<div id="user">
<div id="username">
<input name="p$lt$ctl01$LogonFormIndice$loginElem$UserName" type="text" maxlength="50" id="p_lt_ctl01_LogonFormIndice_loginElem_UserName" placeholder="E-mail" />
<span class="CMSValidator"><span id="p_lt_ctl01_LogonFormIndice_loginElem_rfvUserNameRequired" title="Please enter a user name." class="profile-validator validator error-message" style="display:none;">
</span></span>
</div>
</div>
<div id="pass">
<div id="password">
<input name="p$lt$ctl01$LogonFormIndice$loginElem$Password" type="password" maxlength="20" id="p_lt_ctl01_LogonFormIndice_loginElem_Password" placeholder="Password" />
<span class="CMSValidator"><span id="p_lt_ctl01_LogonFormIndice_loginElem_rfvPasswordRequired" class="profile-validator validator error-message" style="visibility:hidden;">
</span></span>
</div>
</div>
<div id="pass-forgot">
<p>Forgot Password</p>
</div>
<div id="submit-button">
<a id="p_lt_ctl01_LogonFormIndice_loginElem_btnLogon" class="buyBtn button" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("p$lt$ctl01$LogonFormIndice$loginElem$btnLogon", "", true, "p_lt_ctl01_LogonFormIndice_MiniLogon", "", false, true))"></a>
</div>
Do I have to do something with
MyHTML_Element.Type = "submit"
And put inside the div id?
I notice that the HTMLDoc1 is Empty..! should it be empty?
I tried the following but nothing displayed or clicked
Const Url$ = "URL"
Dim UserName As String, Password As String, LoginData As Worksheet
Set LoginData = ThisWorkbook.Worksheets("MySheet")
UserName = LoginData.Cells(1, "K").Value
Password = LoginData.Cells(2, "K").Value
Dim iex As Object
Set iex = CreateObject("InternetExplorer.Application")
With iex
.Navigate Url
ieBusy iex
.Visible = True
Dim oLogin As Object, oPassword As Object
iex.Document.querySelector(".username [id='p_lt_ctl01_LogonFormIndice_loginElem_UserName']").Focus
Set oLogin = iex.Document.querySelector(".username [id='p_lt_ctl01_LogonFormIndice_loginElem_UserName']").Value = ""
Set oPassword = iex.Document.querySelector(".password [type=password]").Value = ""
oLogin.Value = UserName
oPassword.Value = Password
iex.Document.getElementById("submit-button").Click
End With
It asks about an Object on
iex.Document.querySelector("id='p_lt_ctl01_LogonFormIndice_loginElem_UserName']").Focus
I am confused by where your actual problem is.
There is an id for the submit
ie.document.getElementById("submit-button").click ' 0r .submit
For username:
ie.document.querySelector("[id='p_lt_ctl01_LogonFormIndice_loginElem_UserName']").value = ""
For password
ie.document.querySelector("[type=password]").value = ""
When entering values it sometimes helps to use .Focus on the element before assigning the .value.
Public Sub GetInfo()
Dim ie As New InternetExplorer
With ie
.Visible = True
.navigate URL
While .Busy Or .readyState < 4: DoEvents: Wend
With .document.querySelector("[id='p_lt_ctl01_LogonFormIndice_loginElem_UserName']")
.Focus
.value = ""
End With
With .document.querySelector("[type=password]")
.Focus
.value = ""
End With
.document.getElementById("submit-button").click
While .Busy Or .readyState < 4: DoEvents: Wend
Stop
'Quit
End With
End Sub

Interact with Iframe Using VBA

I need to access this website, click in "Entrar" and then interact with the popup (that is an iframe).
And, using the URL of the iframe is not an option.
My code:
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim url As String
url = "https://agenciavirtual.light.com.br/AGV/"
Set ie = New SHDocVw.InternetExplorer
ie.Visible = True
ie.Navigate url
While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set doc = ie.Document
Dim iframeDoc As MSHTML.HTMLDocument
Set iframeDoc = doc.Frames(0).Document
If iframeDoc Is Nothing Then
MsgBox "IFrame was not found."
ie.Quit
Exit Sub
End If
iframeDoc.getElementsByTagName("input")(0).innertext = "123"
iframeDoc.getElementsByTagName("input")(1).innertext = "1234567890"
iframeDoc.getElementsByTagName("button")(0).Click
ie.Quit
The following line generates the error "Acess is denied"
iframeDoc = doc.Frames(0).Document
I've tried other ways like
'Generates the error "Automation Error"
IE.Document.getElementsbyTagName("iframe")(0).contentDocument.getElementsbyTagName("input")(0).innerText = "123"
'Generates the error "Method 'frames' of object 'JScriptTypeInfo' failed"
IE.Document.Frames(0).Document.forms(0).innerText
Main page HTML
<html>
<head>...</head>
<body>
<iframe class="suaIframe" src="https://suav2.light.com.br/Home/Login?DominioCanal=https://agenciavirtual.light.com.br/AGV&PlataformaVersao=Z52&ReturnUrl=/AGV/Autenticacao/LoginSUA&Servico=8&fullScreen=false"></iframe>
</body>
</html>
Iframe HTML
<html>
<head>...</head>
<body>
...
<input class="itemForm" id="CPFCNPJ" maxlength="3" name="CPFCNPJ" onkeypress="return onlyNumbers(this, event);" placeholder="Preencha somente com os 3 primeiros dígitos" type="tel" value="">
<input class="itemForm" id="PN" maxlength="10" name="PN" onkeypress="return onlyNumbers(this, event);" placeholder="Informe o código do cliente" type="tel" value="">
<button type="button" name="btnEntrar" id="btnEntrar" class="btn btn-primary btn-entrar" value="entrar">Entrar</button>
...
</body>
</html>

VBA HTML Coding , Trying To copy Table

I'm trying to pull Table Data from a website after VBA has already opened and clicked Run on the website. But now having trouble trying to copy all the data over to a sheet. I've tried several different codes to try this posted below. Any help would be great.
Here is the code that I have so far .
Sub AHT()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/reporting/main.php?p=centeraht"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
End Sub
I have Tried difference Variations of
Set TDelements = appIE.Docuemnt.getElementsByTagName("TD").innerText
Sheet1.Cells.ClearContents
r = 0
For Each TDelement In TDelements
'Look for required TD elements - this check is specific to VBA Express forum - modify as required
If TDelement.className = "<>" Then
Sheet13.Range("A1").Offset(r, 0).Value = TDelement.innerText
r = r + 1
End If
Next
And this :
Sub Extract_TD_text()
Dim URL As String
Dim IE As InternetExplorer
Dim HTMLDOC As HTMLDocument
Dim TDelements As IHTMLElementCollection
Dim TDelement As HTMLTableCell
Dim r As Long
'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
URL = "http://cctools/reporting/main.php?p=centeraht"
Set IE = New InternetExplorer
With IE
.Navigate URL
.Visible = True
'Wait for page to load
While .Busy Or .ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In IE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
Set TDelements = appIE.Docuemnt.getElementsByTagName("TD").innerText
Sheet1.Cells.ClearContents
r = 0
For Each TDelement In TDelements
'Look for required TD elements - this check is specific to VBA Express forum - modify as required
If TDelement.className = "data xsmall" Then
Sheet13.Range("A1").Offset(r, 0).Value = TDelement.innerText
r = r + 1
End If
Next
But All with no luck. Here is the Source Code of the website after the vba code has already clicked RUn and Generated the Table
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Reporting</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="/inc/framework_style.css" type="text/css" />
<link rel="stylesheet" href="/inc/jquery-ui-1.8.16.custom.css" type="text/css" />
<script type="text/javascript" src="/inc/ajax.js"></script>
<script type="text/javascript" src="/inc/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="/inc/jquery-ui-1.8.16.custom.min.js"></script>
<link rel="stylesheet" href="inc/style.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="menu"><span class='menuheader'>Menu</span>:<br />
<a href='main.php?p=main'>Home</a><br />
<a href='main.php?p=lobscorecard'>LOB Scorecard</a><br />
<a href='main.php?p=vdn'>VDN Report</a><br />
<a href='main.php?p=centeraht'>UV T1 Center AHT Interval</a><br />
<a href='main.php?p=centerahtd'>UV T1 Center AHT Daily</a><br />
<a href='main.php?p=centert2aht'>UV T2 Center AHT Interval</a><br />
<a href='main.php?p=centerT2ahtd'>UV T2 Center AHT Daily</a><br />
<br />
</div>
<div id='fakeheader'></div>
<div id="main"> <script type='text/javascript'>
//<![CDATA[
document.title = 'Reporting - U-Verse T1 AHT Interval - Center Split';
$(document).ready(function(){
document.getElementById('subpagetitle').innerHTML='U-Verse T1 AHT Interval - Center Split';
});
//]]>
</script>
<form method='post' action=''><table class='data'><tr><th>Date</th><th>SubLOB</th><th class='t_custom' title='Comma separated list of agent skills' style='cursor:help; display: none;'>Skills</th></tr><tr><td><input type='text' size='8' id='date' name='date' value='2014-07-13' /></td><td><select name='sublob' onchange="if (this.value == 4) { $('.t_custom').show(); } else { $('.t_custom').hide(); }"><option value=''>All</option><option value='1'>IPDSLAM/CSI</option><option value='2'>Non IPDSLAM/CSI</option><option value='3'>New Blue</option><option value='4'>Custom</option></select></td><td class='t_custom' style='display: none;'><input type='text' name='skills' value='' /></td></tr><tr><th class='center' colspan='3'><input type='submit' value='Run' /></th></tr></table></form> <script type='text/javascript'>
//<![CDATA[
$('#date').datepicker({dateFormat: 'yy-mm-dd',minDate:'2010-05-26',maxDate:'2014-07-13',showOn:'button',buttonImageOnly: true, buttonImage: '/img/icon_pickdate.gif'});
//]]>
</script>
Running for 2014-07-12 22:00:00 to 2014-07-13 15:32:49<br/>
Skills Used: 330,325,334,329,331,332,327,328,336,323,361,351,352,353,354,355,357,358,359,356,348,371,375,368,379,347,385,337,338,339,341,343,344,177,176<br/>
<table class='data xsmall'>
<tr><th rowspan='2'>Int</th>
<th colspan='3' class='center'>ACD Calls</th>
<th colspan='3' class='center'>Avg ACD</th>
<th colspan='3' class='center'>Avg ACW</th>
<th colspan='3' class='center'>Avg Hold</th>
<th colspan='3' class='center'>AIHT</th>
<th colspan='3' class='center'>AOHT</th><th rowspan='2' class='center'>Forecast<br/>AHT</th><th colspan='3' class='center'>AIHT+AOHT</th></tr>
<tr><th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th><th>SAT</th><th>PHX</th><th>Combined</th>
<th>SAT</th><th>PHX</th><th>Combined</th></tr><tr><td>0000</td><td>5</td><td>13</td>
<td>18</td><td>7.993</td><td>5.533</td><td>6.217</td><td>1.013</td><td>0.536</td>
<td>0.669</td><td>1.360</td><td>0.460</td><td>0.710</td><td>10.367</td><td>6.529</td>
<td>7.595</td><td>0.000</td><td>0.117</td><td>0.084</td><td>0.000</td><td>10.367</td>
<td>6.646</td><td>7.680</td></tr><tr class='altrow'><td>0530</td><td>0</td><td>0</td>
<td>0</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td><td>0.000</td>
<td>0.000</td><td>0.000</td></tr><tr><td>0600</td><td>11</td><td>0</td><td>11</td>
<td>22.050</td><td>0.000</td><td>22.050</td><td>2.126</td><td>0.000</td><td>2.126</td>
<td>0.956</td><td>0.000</td><td>0.956</td><td>25.132</td><td>0.000</td><td>25.132</td>
<td>0.000</td><td>0.000</td><td>0.000</td><td>13.825</td><td>25.132</td><td>0.000</td>
<td>25.132</td></tr><tr class='altrow'><td>0630</td><td>20</td><td>0</td><td>20</td>
<td>21.952</td><td>0.000</td><td>23.863</td><td>3.380</td><td>0.000</td><td>3.380</td>
<td>2.262</td><td>0.000</td><td>2.354</td><td>27.593</td><td>0.000</td><td>29.597</td><td>1.576</td><td>0.000</td><td>1.576</td><td>14.839</td><td>29.169</td><td>0.000</td><td>31.172</td></tr><tr><td>0700</td><td>42</td><td>12</td><td>54</td><td>17.212</td><td>7.740</td><td>15.107</td><td>1.444</td><td>0.368</td><td>1.205</td><td>2.442</td><td>0.826</td><td>2.083</td><td>21.099</td><td>8.935</td><td>18.396</td><td>0.561</td><td>0.171</td><td>0.474</td><td>15.983</td><td>21.660</td><td>9.106</td><td>18.870</td></tr><tr class='altrow'><td>0730</td><td>73</td><td>9</td><td>82</td><td>13.539</td><td>15.046</td><td>13.705</td><td>1.005</td><td>1.272</td><td>1.035</td><td>2.057</td><td>1.059</td><td>1.947</td><td>16.602</td><td>17.378</td><td>16.687</td><td>0.142</td><td>0.681</td><td>0.201</td><td>15.867</td><td>16.743</td><td>18.059</td><td>16.888</td></tr><tr><td>0800</td><td>86</td><td>20</td><td>106</td><td>12.600</td><td>15.325</td><td>13.114</td><td>1.924</td><td>0.767</td><td>1.705</td><td>1.237</td><td>1.394</td><td>1.267</td><td>15.761</td><td>17.486</td><td>16.086</td><td>0.715</td><td>0.014</td><td>0.582</td><td>15.250</td><td>16.475</td><td>17.500</td><td>16.669</td></tr><tr class='altrow'><td>0830</td><td>70</td><td>19</td><td>89</td><td>13.039</td><td>20.487</td><td>14.629</td><td>1.552</td><td>1.546</td><td>1.551</td><td>1.995</td><td>5.735</td><td>2.793</td><td>16.586</td><td>27.768</td><td>18.973</td><td>1.098</td><td>0.107</td><td>0.887</td><td>17.333</td><td>17.685</td><td>27.875</td><td>19.860</td></tr><tr><td>0900</td><td>79</td><td>33</td><td>112</td><td>11.347</td><td>17.452</td><td>13.146</td><td>1.410</td><td>1.835</td><td>1.536</td><td>1.438</td><td>5.544</td><td>2.648</td><td>14.195</td><td>24.831</td><td>17.329</td><td>0.624</td><td>1.274</td><td>0.815</td><td>17.065</td><td>14.819</td><td>26.105</td><td>18.144</td></tr><tr class='altrow'><td>0930</td><td>62</td><td>58</td><td>120</td><td>11.863</td><td>9.514</td><td>10.728</td><td>1.278</td><td>1.530</td><td>1.400</td><td>1.868</td><td>2.609</td><td>2.226</td><td>15.009</td><td>13.654</td><td>14.354</td><td>0.705</td><td>0.721</td><td>0.713</td><td>16.625</td><td>15.714</td><td>14.375</td><td>15.067</td></tr><tr><td>1000</td><td>73</td><td>39</td><td>112</td><td>12.805</td><td>13.308</td><td>12.980</td><td>1.366</td><td>1.086</td><td>1.269</td><td>1.723</td><td>2.753</td><td>2.081</td><td>15.893</td><td>17.147</td><td>16.330</td><td>0.360</td><td>0.753</td><td>0.497</td><td>17.275</td><td>16.253</td><td>17.900</td><td>16.827</td></tr><tr class='altrow'><td>1030</td><td>106</td><td>30</td><td>136</td><td>10.530</td><td>15.892</td><td>11.713</td><td>2.047</td><td>1.909</td><td>2.016</td><td>1.658</td><td>3.136</td><td>1.984</td><td>14.234</td><td>20.937</td><td>15.712</td><td>0.341</td><td>1.141</td><td>0.517</td><td>17.139</td><td>14.574</td><td>22.078</td><td>16.230</td></tr><tr><td>1100</td><td>98</td><td>44</td><td>142</td><td>9.911</td><td>14.486</td><td>11.329</td><td>1.027</td><td>0.799</td><td>0.956</td><td>0.888</td><td>2.059</td><td>1.251</td><td>11.825</td><td>17.344</td><td>13.535</td><td>0.630</td><td>0.203</td><td>0.498</td><td>16.017</td><td>12.455</td><td>17.547</td><td>14.033</td></tr><tr class='altrow'><td>1130</td><td>93</td><td>60</td><td>153</td><td>10.327</td><td>12.664</td><td>11.243</td><td>1.621</td><td>1.053</td><td>1.398</td><td>1.052</td><td>1.229</td><td>1.122</td><td>13.000</td><td>14.946</td><td>13.763</td><td>0.369</td><td>0.268</td><td>0.329</td><td>16.751</td><td>13.369</td><td>15.214</td><td>14.092</td></tr><tr><td>1200</td><td>107</td><td>61</td><td>168</td><td>11.503</td><td>13.919</td><td>12.380</td><td>1.101</td><td>0.948</td><td>1.046</td><td>1.538</td><td>1.524</td><td>1.533</td><td>14.143</td><td>16.391</td><td>14.959</td><td>0.851</td><td>0.526</td><td>0.733</td><td>15.800</td><td>14.994</td><td>16.917</td><td>15.692</td></tr><tr class='altrow'><td>1230</td><td>127</td><td>60</td><td>187</td><td>9.198</td><td>12.893</td><td>10.384</td><td>1.638</td><td>0.870</td><td>1.392</td><td>0.814</td><td>0.971</td><td>0.864</td><td>11.650</td><td>14.734</td><td>12.639</td><td>0.690</td><td>0.506</td><td>0.631</td><td>16.217</td><td>12.340</td><td>15.240</td><td>13.270</td></tr><tr><td>1300</td><td>105</td><td>50</td><td>155</td><td>11.266</td><td>13.160</td><td>11.877</td><td>1.067</td><td>0.825</td><td>0.989</td><td>0.603</td><td>0.668</td><td>0.624</td><td>12.936</td><td>14.653</td><td>13.490</td><td>0.917</td><td>1.330</td><td>1.050</td><td>16.271</td><td>13.853</td><td>15.983</td><td>14.540</td></tr><tr class='altrow'><td>1330</td><td>105</td><td>59</td><td>164</td><td>11.154</td><td>13.355</td><td>11.946</td><td>1.243</td><td>0.844</td><td>1.100</td><td>0.620</td><td>1.049</td><td>0.774</td><td>13.017</td><td>15.248</td><td>13.819</td><td>1.130</td><td>0.923</td><td>1.055</td><td>16.908</td><td>14.147</td><td>16.171</td><td>14.875</td></tr><tr><td>1400</td><td>95</td><td>50</td><td>145</td><td>15.041</td><td>19.103</td><td>16.441</td><td>1.443</td><td>1.386</td><td>1.423</td><td>1.683</td><td>1.796</td><td>1.722</td><td>18.166</td><td>22.285</td><td>19.586</td><td>0.926</td><td>0.472</td><td>0.770</td><td>17.075</td><td>19.093</td><td>22.757</td><td>20.356</td></tr><tr class='altrow'><td>1430</td><td>99</td><td>70</td><td>169</td><td>13.438</td><td>14.066</td><td>13.698</td><td>1.331</td><td>0.935</td><td>1.167</td><td>1.942</td><td>1.553</td><td>1.781</td><td>16.711</td><td>16.553</td><td>16.646</td><td>0.948</td><td>1.363</td><td>1.120</td><td>17.000</td><td>17.659</td><td>17.916</td><td>17.765</td></tr><tr><td>1500</td><td>84</td><td>78</td><td>162</td><td>14.921</td><td>13.699</td><td>14.333</td><td>1.390</td><td>1.162</td><td>1.280</td><td>1.872</td><td>1.295</td><td>1.594</td><td>18.183</td><td>16.156</td><td>17.207</td><td>1.286</td><td>0.859</td><td>1.080</td><td>17.575</td><td>19.469</td><td>17.015</td><td>18.287</td></tr><tr class='altrow'><td>1530</td><td>67</td><td>63</td><td>130</td><td>18.298</td><td>14.476</td><td>16.446</td><td>1.833</td><td>0.850</td><td>1.357</td><td>1.863</td><td>0.979</td><td>1.435</td><td>21.995</td><td>16.306</td><td>19.238</td><td>1.398</td><td>1.207</td><td>1.305</td><td>16.475</td><td>23.392</td><td>17.513</td><td>20.543</td></tr><tr><td>1600</td><td>74</td><td>61</td><td>135</td><td>17.055</td><td>18.697</td><td>17.797</td><td>2.100</td><td>1.473</td><td>1.817</td><td>1.655</td><td>2.616</td><td>2.089</td><td>20.810</td><td>22.786</td><td>21.703</td><td>0.823</td><td>0.807</td><td>0.816</td><td>16.850</td><td>21.634</td><td>23.593</td><td>22.519</td></tr><tr class='altrow'><td>1630</td><td>67</td><td>71</td><td>138</td><td>17.288</td><td>13.447</td><td>15.312</td><td>2.450</td><td>1.115</td><td>1.763</td><td>2.284</td><td>1.648</td><td>1.957</td><td>22.022</td><td>16.211</td><td>19.032</td><td>1.534</td><td>1.423</td><td>1.477</td><td>16.181</td><td>23.556</td><td>17.634</td><td>20.509</td></tr><tr><td>Total</td>
<td>1748</td><td>960</td><td>2708</td><td>12.846</td><td>14.207</td><td>13.329</td>
<td>1.521</td><td>1.108</td><td>1.375</td><td>1.478</td><td>1.821</td><td>1.600</td>
<td>15.846</td><td>17.137</td><td>16.303</td><td>0.799</td><td>0.813</td><td>0.804</td>
<td>16.622</td><td>16.644</td><td>17.950</td><td>17.107</td></tr>
</table><br/>
<a href='csvexport.php'>CSV Export</a><br/></div>
<div id="fakefooter"></div>
</div>
<div id="footer"><p><span class='copyright'>© 2014</span></p></div>
<div id="header"><div class='left'><img src='/img/pace_logo_smaller.gif' alt='Pace Logo' /></div><div class='right'><div style='float: right;'>User: [<a href='index.php?logout=1'>Logout</a>]<br />Access Level: User<br /></div></div><span class='subtitle' style='cursor:pointer;' onclick="document.location='main.php';">Reporting</span><br/><span id='subpagetitle'></span></div>
</body>
</html>
Was able to get the oode to work using the copy and paste it all. And use two more subs to clear out extra items not needed .
Global slogininfo As String
Global appIE As Object ' InternetExplorer.Application
Global sURL As String
Global sLogin As String
Global sNotes As String
Global ID As Object ' MSHTML.IHTMLElement
Global infraction As Object ' MSHTML.IHTMLElement
Global Element As Object ' HTMLButtonElement
Global Btninput As Object ' MSHTML.HTMLInputElement
Global ElementCol As Object ' MSHTML.IHTMLElementCollection
Sub AHT()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/reporting/main.php?p=centeraht"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = "Run" Then
Btninput.Click
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:2")
appIE.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
appIE.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT
appIE.Quit
Range("A1").Select
ActiveSheet.Paste
Call Cleanup
Call DeleteObj
End Sub
Sub Cleanup()
'
' Cleanup Macro
'
'
Rows("1:15").Select
Range("A15").Activate
Selection.Delete Shift:=xlUp
ActiveWindow.SmallScroll Down:=-24
End Sub
Sub DeleteObj()
Dim obj As Object
For Each obj In ActiveSheet.Shapes
obj.Delete
Next
End Sub
Now with another site I had issues with the copy and paste method wasn't working. But the site has a CSV option to download the date i altered the code to capture that and paste it as such.
Sub Metrics()
Application.ScreenUpdating = False
Application.ScreenUpdating = True
Set appIE = CreateObject("InternetExplorer.Application")
sURL = "http://cctools/rportal/main.php?p=agentavaya"
' Instructes the macro to open IE and navigate to sURL.
With appIE
.Navigate sURL
.Visible = True
Application.Wait Now + TimeValue("00:00:02")
Set HTMLDOC = .Document
End With
Application.Wait Now + TimeValue("00:00:02")
For Each Btninput In appIE.Document.getElementsByTagName("INPUT")
If Btninput.Value = " Run " Then
Btninput.Click
Exit For
End If
Next
Application.Wait Now + TimeValue("00:00:04")
Call CSV
End Sub
Sub CSV()
sCSVLink = "http://cctools/rportal/csvexport.php"
sfile = "csvexport.php"
ssheet = "Sheet10"
Set wnd = ActiveWindow
Application.ScreenUpdating = False
Workbooks.Open Filename:=sCSVLink
Windows(sfile).Activate
ActiveSheet.Cells.Copy
wnd.Activate
Range("A1").Select
ActiveSheet.Paste
Application.DisplayAlerts = False
Windows(sfile).Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub