簡體   English   中英

IE 自動化 - Excel VBA

[英]IE Automation - Excel VBA

我正在嘗試通過 Excel VBA 代碼進行 IE 自動化。

我有一個包含頂部、中間和結果表單的網頁。 我需要在中間表單中輸入值,但無法從中獲取任何控件並將其設為 0。即,Document.forms.Length 給出 0。也嘗試了下面的代碼,但不起作用。

Ie.Document.forms("SearchForm").elements("PolicyNumber").Value = "Josh"

看起來這個表單在一個框架上,但在 HTML 代碼中看不到框架引用。 HTML代碼如下:

<body bgcolor="white"> 
    <form method=POST name="SearchForm" action="PolicySearch" target="resultframe" > 
        <input type=hidden name="NewSearch" value="True" ></input> 
        <table class=box2 cellpadding="1" cellspacing="0" border="0" width="760" align="top" halign="left"> 
            <tr> 
            <td class="name" align="left">
                Policy# :<input type=text name="PolicyNumber" maxlength="10" value="" size="10"></input>
            </td>

試試看

Ie.Document.getElementsByName("PolicyNumber").Item(0).Value="Josh"

或者

Iie.Document.getElementsByName("PolicyNumber").Value="Josh"

嘗試這個:

聲明一個新變量:

Dim Elements As IHTMLElementCollection

使用表單和標簽名稱設置元素,例如。 輸入

Set Elements = IE.Document.forms("SearchForm").Document.getElementsByTagName("input")

將值傳遞給文本/輸入

Elements("PolicyNumber").Value = "Josh"

and need to add MS HTML Objects library in the references.注意:上面的代碼原本是針對,需要在references中添加MS HTML Objects庫 雖然您可以通過聲明為對象來使用元素,但聲明為 IHTMLElementCollection 將在您按下“.”時產生事件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM