2017-09-11 11 views
1

私のコードの目的は、指定された基準でウェブサイト上でレポートを実行することです。私はすべての "距離"の基準を検索したいと思います。私は確信しているかどうかを尋ねるメッセージボックスを表示します。自分のコードで「OK」ボタンをクリックできるようにしたい。しかし、 "送信"ボタンがヒットしたら、私のコードは実行を停止し、 "OK"ボタンが押されるまで停止します。VBAスクリプトのJavascript確認ボタンをクリック

注:私は、HTMLやJavaScript

を変更することはできませんここではVBAコード

Sub Data_Grab() 

'Open Internet Explorer and webpage 
Dim IE As Object 
Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.Navigate "insert website here" 

'wait for page to finish loading 
Do While IE.Busy 
Loop 

'get a reference to the search form by finding the id in the web page's object model 
Dim daysAs Object 
Dim city As Object 
Set days= IE.Document.getElementByID("age"): days.Value = "10" 
Set city= IE.Document.getElementByID("location"): city.Value = "LA"  

'click the search button 
With IE.Document 
    Set elems = .getElementsByTagName("input") 
    For Each e In elems  
     If (e.getAttribute("value") = "Submit") Then 
      e.Click 
      Exit For 
     End If 
    Next e 
End With 
End Sub 

ウェブサイトのソース

if (!distanceSelect) { 
    proceed = confirm("Are you sure you wish to search all " + question + "? Performance issues may occur."); 
} else {proceed = true;} 

そして

<input class="contentarea" type="button" value="Submit" id="submit" onclick="javascript:loadReport();" /> 
から関連するHTML/JavaScriptのコードです

SendKeysやShellScriptの作成など、さまざまなソリューションを試してみましたが、いずれも動作させることができませんでした。

ありがとうございます。

答えて

1

一つの方法は、execScriptconfirmを上書きするために、次のようになります。

Dim ie As Object, win As Object 
Set ie = CreateObject("InternetExplorer.Application") 
ie.Visible = True 
ie.Navigate "https://stackoverflow.com" 

Do While ie.Busy: DoEvents: Loop 

Set win = ie.Document.parentWindow 
win.execScript "window.confirm = function(){return true;};" 
+0

働いたこと!ありがとうございました – user8594596

関連する問題