VBA HTML Coding , Trying To copy Table - html

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

Related

How to click on "Create Issue" button in Excel VBA

Hi i'm trying to get the "Create an Issue" button to click after filling out a form online. The form fills correctly I just need it to do the final piece and click on the "Create Issue".
Here's my setup and code
Microsoft Excel 2016 32bit
VBA:
Option Explicit
Sub Waiting()
Application.Wait (Now + TimeValue("0:00:2"))
End Sub
Sub IE_Wait(IE As InternetExplorer)
With IE
While .Busy Or .ReadyState <> READYSTATE_COMPLETE
DoEvents
Call Waiting
' SendKeys "{ENTER}"
Wend
While .Document.ReadyState <> "complete"
DoEvents
Call Waiting
'SendKeys "{ENTER}"
Wend
End With
End Sub
Sub FindAndTerminate(ByVal strProcName As String)
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcName & "'")
If colProcess.Count > 0 Then
For Each objProcess In colProcess
On Error Resume Next
objProcess.Terminate
Next objProcess
End If
End Sub
Public Sub make_tickets_with_me()
Dim IE As InternetExplorer
Dim HTMLdoc As HTMLDocument
Dim x, Site, ASIN_1, ASIN_2, ASIN_3, ASIN_4, ASIN_5 As String
Dim ws As Worksheet
Dim e
Dim y, lLastRow As Long
' Kill any currently running Explorer Windows
FindAndTerminate "iexplore.exe"
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Set IE = New InternetExplorerMedium
With ThisWorkbook
lLastRow = Worksheets("ASINs").Cells(Rows.Count, "A").End(xlUp).Row 'Count total Asins
x = 2
For x = 2 To lLastRow
Debug.Print x
ASIN_1 = Worksheets("ASINs").Range("A" & x).Value
ASIN_2 = Worksheets("ASINs").Range("A" & x + 1).Value
ASIN_3 = Worksheets("ASINs").Range("A" & x + 2).Value
ASIN_4 = Worksheets("ASINs").Range("A" & x + 3).Value
ASIN_5 = Worksheets("ASINs").Range("A" & x + 4).Value
Site = "https://sim.amazon.com/issues/create?assignedFolder=5aec25c2-1135-4d36-b751-37d967c0a83e&title=Zappos+Unsellable+Test&description=Below+is+a+list+of+5+asins+that+are+unsellable%3A%20%0D%0A%0D%0A" + ASIN_1 + "%0D%0A" + ASIN_2 + "%0D%0A" + ASIN_3 + "%0D%0A" + ASIN_4 + "%0D%0A" + ASIN_5 + "%0D%0A%0D%0A&descriptionContentType=text%2Fplain&extensions%5Btt%5D%5Bimpact%5D=4&extensions%5Btt%5D%5Bcategory%5D=&authorizations%5B%5D=BREAK&authZCompression=v1"
x = x + 4
' Debug.Print ASIN_1 & ASIN_2 & ASIN_3 & ASIN_4 & ASIN_5
' Debug.Print x
' Debug.Print Site
''' BEGIN INTERACTION WITH IE
Set IE = New InternetExplorerMedium
With IE
.Visible = True
.Left = 25
.Top = 25
.Height = 700
.Width = 1300
AppActivate ("Internet Explorer")
.Navigate Site
IE_Wait IE
Call Waiting
IE_Wait IE
Call Waiting
Set e = IE.Document.getElementsByTagName("span")
->>>>>>>If e.innerText = "Create an issue In Zappos Unsellable: Tickets" Then
e.parentElement.Click
Exit For
End If
'Set e = IE.Document.getElementsByClassName("create")(0)
'e.Click
' SendKeys "{NUMLOCK}"
Call Waiting
.Quit
End With
Next 'Loop for x=2 to lLastRow, Adds 4 to x, then Next adds 1 to total of 5 per iteration
ThisWorkbook.Worksheets("Buttons").Activate
MsgBox ("Tickets Created :)")
End With
End Sub
I've added an arrow to where the error is.
Here's the Inspect for the button I want to click
</div>
<div class="clearfix"></div>
<script type="jsv/50_"></script></div></section>
<section class="wizard-step " id="wizard-step-2" data-wizard-step="2"><div data-module-name="App.Views.CreateWizardStep" data-template="#create-wizard-step-template"><script type="jsv#112_"></script>
<div class="form-actions">
<div class="view-state-initialized-visible" data-view="create">
<button class="btn btn-primary btn-large" type="submit" data-csm-counter="createViewCreateButton">
<span style="display: inline;" data-link="visible{:!~isUndefined(issue.assignedFolder)}"><span id="view-tag-157" data-module-name="App.Views.FolderDisplayView" data-template="undefined"><script type="jsv#170_"></script><span style="display: inline;" data-name="folder-label-completed-text" data-link="visible{:state == 'completed'}">
<script type="jsv#219^"></script><script type="jsv#308_"></script>
<script type="jsv#388^"></script>Zappos Unsellable: Tickets
Create an issue in
<script type="jsv/388^"></script>
<script type="jsv/308_"></script><script type="jsv/219^"></script>
</span><span style="display: none;" data-link="visible{:state == 'loading'}">
<script type="jsv#172_"></script><i class="icon-spinner"></i><script type="jsv/172_"></script>
Loading folder...
</span><span style="display: none;" data-link="visible{:state == 'errored'}">
Could not find folder
</span><span style="display: none;" data-link="visible{:state == 'empty'}">
Folder not specified
</span><script type="jsv/170_"></script></span>
</span>
<span style="display: none;" data-link="visible{:~isUndefined(issue.assignedFolder)}">
Create an issue
</span>
</button>
<div class="alert alert-error pull-right" style="display: none;" data-link="visible{:!state.isValid}">
Please correct the errors above
</div>
</div>
<div class="view-state-loading-visible alert alert-info" data-view="create">
<script type="jsv#113_"></script><i class="icon-spinner"></i><script type="jsv/113_"></script>
Creating your issue...
</div>
<div class="view-state-errored-visible alert alert-error" data-view="create">
<strong>There was an error creating your issue:</strong>
<div data-link="html{>state.createError}"></div>
<button class="btn btn-primary pull-right" type="submit" data-csm-counter="createViewTryAgainButton">
Try again
</button>
<div class="clearfix"></div>
</div>
<div class="view-state-redirecting-visible alert alert-success" data-view="create">
Redirecting you to
<a href="/issues/undefined" data-link="href{:'/issues/' + issue.id} data-issue-id{htmlAttr:issue.id}" data-issue-id="">
your new issue
</a>
</div>enter code here
Any help would be appreciated i'm trying to edit another persons VBA that left.
You can try a combination of css selectors
ie.document.querySelector("button[data-csm-counter=createViewTryAgainButton]").click

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>

Extracting div class information from website with VBA

I've been trying to scrape the following page for research purposes: http://www.brazil4export.com/en/pesquisa/resultado/?page=1&
A piece of HTML I want to get information from is the following:
<div class="panel panel-default">
<div class="panel-heading" data-activity="22196 - Manufacturer" data-products='["Products", "Information"]' data-range="Value" data-contact="Person" data-site="www.website.com.br" data-emails="name#example.com" data-phones="Phone" data-address="Street / City" data-countries='["Country1", "Country2"]' data-name="ACME Corp.">
<h3 class="panel-title">
<button class="btn btn-link" data-toggle="modal" data-target="#company-modal">
ACME Corp.
</button>
</h3>
<button class="btn btn-primary btn-lg pull-right" data-toggle="modal" data-target="#company-modal">
<i class="icon-plus"></i>
</button>
</div>
</div>
For each result on the page, there's a <div class="panel panel-default">, just as the above, and I want to get the data-name and data-site information from each of them. This is what I've tried, so far:
Sub useClassnames()
Dim element As IHTMLElement
Dim elements As IHTMLElementCollection
Dim ie As InternetExplorer
Dim html As HTMLDocument
'open Internet Explorer in memory, and go to website
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "http://www.brazil4export.com/en/pesquisa/resultado/?page=1&"
'Wait until IE has loaded the web page
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Loading Web page …"
DoEvents
Loop
Set html = ie.document
Set elements = html.getElementsByClassName("panel panel-default")
Dim erow As Long
For Each element In elements
If element.className = "data-name" Then
erow = Sheet1.Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 2) = html.getElementsByClassName("data-name").innerText
End If
If element.className = "data-site" Then
erow = Sheet1.Cells(Rows.count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 3) = html.getElementsByClassName("data-site").innerText
End If
Next element
End Sub
It doesn't work, but doesn't show me any errors as well.
Run this and you will have all the results:
Sub WebData()
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim source As Object
With http
.Open "GET", "http://www.brazil4export.com/en/pesquisa/resultado/?page=1&", False
.send
html.body.innerHTML = .responseText
End With
For Each source In html.getElementsByClassName("panel-heading")
x = x + 1: Cells(x, 1) = source.getAttribute("data-Name")
Cells(x, 2) = source.getAttribute("data-site")
Next source
End Sub
Make sure to add "Microsoft Html Object Library" and "Microsoft xml" to the reference library. See the picture of the results:

Webpage login not working Using excel VBA

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