【发布时间】:2015-04-19 04:34:23
【问题描述】:
我正在尝试使用 excel VBA 来自动输入我公司内联网网页上的数据。我知道如何与字段具有“id”的网页的值进行交互,就像下面的 html 代码中一样
<input name="txtUserName" tabindex="1" id="txtUserName" type="text">
有了这种 html 代码,我会使用类似
IE.Document.getElementbyId("txtUserName").Value = "UserName"
我面临的问题是与我尝试交互的字段相关的代码是
<HTML><HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">
<SCRIPT type=text/javascript>
function ajusterFrames() {
var iLargeurGauche = 217;
var iLargeurDroite = 850;
var iLargeurFenetre = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var iMarge = 0;
var sCols = "";
if (iLargeurFenetre > (iLargeurGauche + iLargeurDroite)) {
iMarge = (iLargeurFenetre - (iLargeurGauche + iLargeurDroite)) / 2;}
sCols = (iLargeurGauche + iMarge) + ",*";
document.getElementById("framesetbas").cols = sCols;
document.getElementById("cadres").style.display = "block";}
window.onload = ajusterFrames;
window.onresize = ajusterFrames;
</SCRIPT>
<TBODY>
<TR> </TR>
<TR>
<TD>
<!--RECHERCHE-->
DIV id=Projet>
<!--RECHERCHE-->
<CENTER>
<FIELDSET style="WIDTH: 600px" name="recherche">
<LEGEND style="FONT-SIZE: 10px; FONT-FAMILY: verdana; COLOR: #767676" name="legende_recherche">
<INPUT onclick=afficherRecherche(this.value); type=radio value=simple name=TypeRecherche>
</DIV><!------RECHERCHE AVANCÉE------------------------------------->
<DIV id=divAvancee>
<CENTER>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TR>
<TR>
<TR>
<TR>
<TR>
<TR>
<TD align=right>
<FONT color=#003366 size=1 face=verdana>No Projet :</FONT></TD>
所以我正在尝试修改字段标识的值:“txtNoProjet”这是我可以想出的代码,我尝试了很多版本,但仍然无法正确。
更新代码以包含解决方案
Private Sub entree_budget()
Dim i As Long
Dim IE As Object
Dim Doc As Object
Dim objElement As Object
Dim objCollection As Object
Dim buttonCollection As Object
Dim valeur_heure As Object
num_proj = Cells(1, 3) 'this is the value that I need to input
' Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
' You can uncoment Next line To see form results
IE.Visible = True
' Send the form data To URL As POST binary request
IE.Navigate "http://intranet.cima.ca/fr/application/paq/projets/index.asp?v1_lang=1"
' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'下面的更新代码
Set links = IE.Document.frames(2).Document.getElementsByTagName("input")
n = links.Length
While i < n
If links(i).Name = "txtMotCle" Then
links(i).Value = num_proj
End If
i = i+ 1
Wend
End Sub
谁能帮我解决这个问题?
如果可以的话,我还需要单击表单底部的“搜索”按钮,但我无法识别它的语法,所以我不知道如何与之交互。有人可以告诉我如何单击具有此 html 代码的按钮吗?
<A href="javascript:submitForm('avancee');">
<IMG border=0 alt="Rechercher un projet" src="../../../images/fr/rechercher.gif"></A>
对此的更新代码解决方案:
Set links = IE.Document.frames(2).Document.getElementsByTagName("a")
n = links.LengtH
i = 0
While i < n
If links(i).href = "javascript:submitForm('avancee');" Then
Set objElement = links(i)
objElement.ClicK
End If
i = i + 1
Wend
非常感谢您花时间回答我的问题。
【问题讨论】:
标签: html excel vba internet-explorer