I am trying to use posttext within a web query to extract data from our intranet. The web page uses a combo box with various options which automatically refreshes the web page with the new data when selected. I am trying to use a macro and posttext to select the data I wish. The macro is written as follows:-
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://intranet/PR/AdvancedSearchScreen2.aspx?Type=1&Level=4&Crit=P181&StartLevel=1&StartParent=" _
, Destination:=Range("A1"))
.PostText = "__EVENTTARGET=DisplaySelect&__EVENTARGUMENT=actual_weight&DisplaySelect=actual_weight"
.Name = _
"AdvancedSearchScreen2.aspx?Type=1&Level=4&Crit=P181&StartLevel=1&StartParent="
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
The relevant part of the source code for the web page shows:-
******** language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.Form1;
}
else {
theform = document.forms["Form1"];
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
*********>
<table cellSpacing="0" cellPadding="0" width="100%">
<tr>
<td><span id="TitleLabel" class="REPORT_HDR">Asset Level Search Report</span></td>
<td align="right"><a id="ExportLink" href="AdvancedSearchExport.aspx?Screen=2&Type=1&Level=4&Crit=P181&FieldName=model_drift_value&AllocLevel=1&ParentCode=" target="_blank">Export to Excel</a>
| <a href="javascript:window.close();">Close Window</a>
</td>
</tr>
<tr height="25">
<td><span id="SearchLabel">You searched on <b>'P181'</b><br></span></td>
<td></td>
</tr>
<tr height="35">
<td><select name="DisplaySelect" onchange="__doPostBack('DisplaySelect','')" language="javascript" id="DisplaySelect" class="TEXTBOX">
<option value="actual_value">Actual Value</option>
<option value="actual_weight">Actual Weight</option>
<option value="breach_value">Breach Value</option>
<option value="breach_weight">Breach Weight</option>
<option selected="selected" value="model_drift_value">Model Drift Value</option>
<option value="model_drift_weight">Model Drift Weight</option>
<option value="benchmark_drift_value">Benchmark Drift Value</option>
<option value="benchmark_drift_weight">Benchmark Drift Weight</option>
Any ideas?
Thanks....
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://intranet/PR/AdvancedSearchScreen2.aspx?Type=1&Level=4&Crit=P181&StartLevel=1&StartParent=" _
, Destination:=Range("A1"))
.PostText = "__EVENTTARGET=DisplaySelect&__EVENTARGUMENT=actual_weight&DisplaySelect=actual_weight"
.Name = _
"AdvancedSearchScreen2.aspx?Type=1&Level=4&Crit=P181&StartLevel=1&StartParent="
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
The relevant part of the source code for the web page shows:-
******** language="javascript" type="text/javascript">
<!--
function __doPostBack(eventTarget, eventArgument) {
var theform;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.Form1;
}
else {
theform = document.forms["Form1"];
}
theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
theform.__EVENTARGUMENT.value = eventArgument;
theform.submit();
}
// -->
*********>
<table cellSpacing="0" cellPadding="0" width="100%">
<tr>
<td><span id="TitleLabel" class="REPORT_HDR">Asset Level Search Report</span></td>
<td align="right"><a id="ExportLink" href="AdvancedSearchExport.aspx?Screen=2&Type=1&Level=4&Crit=P181&FieldName=model_drift_value&AllocLevel=1&ParentCode=" target="_blank">Export to Excel</a>
| <a href="javascript:window.close();">Close Window</a>
</td>
</tr>
<tr height="25">
<td><span id="SearchLabel">You searched on <b>'P181'</b><br></span></td>
<td></td>
</tr>
<tr height="35">
<td><select name="DisplaySelect" onchange="__doPostBack('DisplaySelect','')" language="javascript" id="DisplaySelect" class="TEXTBOX">
<option value="actual_value">Actual Value</option>
<option value="actual_weight">Actual Weight</option>
<option value="breach_value">Breach Value</option>
<option value="breach_weight">Breach Weight</option>
<option selected="selected" value="model_drift_value">Model Drift Value</option>
<option value="model_drift_weight">Model Drift Weight</option>
<option value="benchmark_drift_value">Benchmark Drift Value</option>
<option value="benchmark_drift_weight">Benchmark Drift Weight</option>
Any ideas?
Thanks....