2016-07-01 6 views
0

私の問題についてはstackoverflowに関する多くのトピックが見つかりましたが、残念ながら特定のウェブサイトの解決策を見つけることができませんでした。VBAプログラミング - ウェブサイト上のjavascriptリンクをクリック

私は銀行のウェブサイトからレポートを自動的に生成するようVBAを試行しています。 私はウェブサイトにアクセスし、ユーザーIDとパスワードを問題なくプラグインできました。私は通常、レポートを生成できるページに達しました。 リンクのクリックをシミュレートする必要があります...しかし、私はそれを行うことはできません。

Here is a screenshot of the website, with the HTML code of the link I have to click on to generate the report (Summary Report Copy)。ここで

は、私が上をクリックする必要があるリンクのHTMLコードです:

<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' &amp; isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false" class="">Summary Report Copy</a> 

私はVBAのコード行を試してみたが、動作しません:

IE.Document .getElementById( "irCustomStepOne:headerDataTableId:23:reportnamestatusは")。FireEvent "onclickの"

誰もが、この "要約報告書のコピー" にVBAのおかげをクリックする方法任意のアイデアを持っていますか?

ありがとうございます!

EDIT:リンクがあるWebページの部分の完全なHTMLコードです。たぶん私は正しいIDを使用していないでしょうか?

<td width="290px"> 
<span id="irCustomStepOne:headerDataTableId:23:reportNmGrp"> 
<a id="irCustomStepOne:headerDataTableId:23:reportnamestatus" href="#" style="float:left;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if(isDateValidForMassPayPD()==\'false\' &amp; isWareHouseRptPD(\'23\') ==\'true\'){RichFaces.$(\'irCustomStepOne:panelWareHouseRptError\').show(event, {\'top\':\'100px\', \'left\':\'300px\'});return false;}else{if(!onReportLink(\'23\')) return false;}','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamestatus\':\'irCustomStepOne:headerDataTableId:23:reportnamestatus\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Run\'},\'_blank\')');return false">Summary Report Copy</a> 
<a id="irCustomStepOne:headerDataTableId:23:reportnamePrint" href="#" style="float:left;display:none;" title="Summary Report Copy" onclick="jsf.util.chain(this,event,'if (!onReportLink(\'23\')) return false;','mojarra.jsfcljs(document.getElementById(\'irCustomStepOne\'),{\'irCustomStepOne:headerDataTableId:23:reportnamePrint\':\'irCustomStepOne:headerDataTableId:23:reportnamePrint\',\'repId\':\'3368127\',\'dayTypeKey\':\'PREVIOUS_DAY\',\'userAction\':\'Print\'},\'_blank\')');return false">Summary Report Copy</a> 
<span id="irCustomStepOne:headerDataTableId:23:rpId" style="float:left;display:none;">3368127</span> 
</span> 
</td> 
+0

あなたは 'IE.Document.getElementByIdを試してみました。click'? –

+0

はい、試しましたが、取得しました: 実行時エラー '424' オブジェクトが必要です これはリンクのIDなのでわかりません... – Cyriaque

+0

ナビゲーションに数秒待ってからドキュメントが完全に読み込まれていないように見えます。これをリンクの上に追加してください: 'Application.Wait(Now + TimeValue(" 0:00:08 "))' –

答えて

0

ページが完全に読み込まれるまで待つ必要があります。何かのように

Do: VBA.DoEvents: Loop While IE.Busy ' wait for the page to load 
Dim el 'As IHTMLElement 
Set el = IE.Document.getElementById("irCustomStepOne:headerDataTableId:23:reportnamestat‌​us") 
If el Is Nothing Then el = IE.Document.querySelector("a[title='Summary Report Copy']") 
If el Is Nothing Then MsgBox("Link not found!") : Exit Sub 
el.click 
Do: VBA.DoEvents: Loop While IE.Busy ' wait for next page to load 
+0

こんにちはスレイイ、ありがとうございました。あなたのコードは、私に "Run Time Error '424' Object Required"を与えます。私は完全なHTMLコードを貼り付けて、ウェブサイトの構造をよりよく理解できるようにします。 私は間違ったリンクをクリックしようとしていますか? – Cyriaque

+0

[ツール]> [参照...]で、[Microsoft Internet Control]および[Microsoft HTML Object Library]を確認します。次に、あなたは 'Dim IE As New SHDocVw.InternetExplorer'のようなものが必要です – Slai

+0

これらの参照は既に残念ながらアクティブ化されています... – Cyriaque

0

これはいつも私のために働いた。それをしてくださいしてみてください( ":headerDataTableId:23:irCustomStepOne reportnamestatus")

For each lnk in IE.Document.getElementByTagName("a") 
If lnk.ID = "irCustomStepOne:headerDataTableId:23:reportnamestat‌​us" Then 
    lnk.Click 
    Exit For 
Next 
+0

これは私に" Run Time Error '424' Object Required "を与えます。 私はウェブサイトの構造をよりよく理解できるように、完全なHTMLコードを貼り付けます。 – Cyriaque

関連する問題