2013-08-06 39 views
1

林其處理與Java腳本提醒我能夠瀏覽和輸入的網頁數據的問題..VBA關閉Java的警報彈出窗口與

名「從網頁的消息」,但選擇不同的項目更新時顯示的模態警報。

如何單擊確定按鈕tru VBA?

任何幫助,請...

這裏是在網頁中我想射擊時,我選擇一個項目觸發警報的代碼..

這是我在HTML腳本中看到:

function onUpdatedShowAlertTS(varControl) { 


if (varControl == "ddlProjectStatus") { 
var varconfirm = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnReleaseStatusConfirmation'); 
if (varconfirm.value == "true") { 
var varControlId = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_ddlProjectStatus'); 
var value = varControlId.options[varControlId.selectedIndex].innerText; 
alert('Release status is reset to ' + value + ' successfully and validation status is Pending.'); 
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnReleaseStatusConfirmation').value = "false"; 
} 
} 


if (varControl == "ddlReleaseName") { 
var varconfirm = document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnReleaseNameConfirmation'); 
if (varconfirm.value == "true") { 
alert('Release status and and validation status is reset successfully.'); 
var isReadOnlyStatus = '0' 
if (!(isReadOnlyStatus == 1)) { 
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnReleaseNameConfirmation').value = "false"; 
document.getElementById('ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_btnSaveValidate').disabled = false; 
} 
} 
} 

這是我的代碼:

ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseChange").Click 
ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseChange").setAttribute "value", "true" 
ieDoc.getElementById("ctl00_Tabs_pnlCaptureTSMetrics_CaptureTSMetrics_hdnConfirmationforReleaseChange").setAttribute "type", "hidden" 

回答

1

一個直接的解決辦法是使用SendKeys功能。

Application.SendKeys "n"   ' Send the latter "n" to the dialog 

Application.SendKeys "{ENTER}" ' Send ENTER to the dialog 

你可以找到SendKeys here更多信息。

+0

謝謝..它的工作原理...我只是有一些澄清...「n」來自哪裏來源?它有什麼用處?雖然,我知道使用sendkeys是不可靠的...我們有其他選擇可以考慮嗎? – Toshi

+0

如果對話框是「是」/「否」提示,我使用了「n」,因此發送一個「n」將選擇「否」。我發現SendKeys大部分時間都在工作。您的其他選項可能是通過自動化Internet Explorer或使用[WinInet]在VBA中創建Web客戶端(http://msdn.microsoft.com/zh-cn/library/windows/desktop/aa385331%28v=vs.85 %29.aspx)。您的客戶可以完成您手動執行的任務。 – ErinsMatthew

+0

你可以給我一些示例代碼如何做到這一點? – Toshi