【发布时间】:2016-09-11 22:07:46
【问题描述】:
我想使用 Excel 值更新网站中的字段。
我在网上找到了这个宏并尝试编辑它。
登录成功后如何更新字段?
我添加了以下参考:
- Microsoft HTML 对象库
- Microsoft Internet 控件
我尝试在 IE8 中运行它。
收到错误:
对象'IWebBrowser2'的方法'Document'在线失败
我更新到IE11,现在错误是:
“自动化错误,未指定错误”
IE.document.getelementsbyname("_58_login").Value = "jigarjigar"
Public Declare PtrSafe Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
Sub Automate_IE_Enter_Data()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
Dim document As HTMLDocument
'Create InternetExplorer Object
Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
'Set IE = CreateObject("InternetExplorer.Application")
'True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Navigate to URL
IE.Navigate https://www.asite.com/login-home/
' Wait while IE loading...
Do While IE.ReadyState = 4: DoEvents: Loop
'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.HWND
'Set IE as Active Window
SetForegroundWindow HWNDSrc
'Find & Fill Out Input Box
IE.document.getelementsbyname("_58_login").Value = "jigarjigar"
IE.document.getelementsbyname("_58_password").Value = "mypassword"
IE.document.getelementsbyclassname("btn-submit nobgcolor").Click
'Unload IE
endmacro:
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
<table class="lfr-table">
<tr>
<td class="label-unm">
Login (Email)
</td>
<td>
<div class="inp-login"><input name="_58_login" type="text" value="jigar@jigar.com" onblur="checkforGSUser(this)" autocomplete="off"/></div>
</td>
</tr>
<tr>
<td class="label-pass">
Password
</td>
<td>
<div class="inp-login"><input id="_58_password" name="_58_password" type="password" autocomplete="off" value="" /></div>
<span id="_58_passwordCapsLockSpan" class="pwdCapsMsgSpan" style="position:absolute;display:none;"><table width="111" border="0" cellspacing="0" cellpadding="0"><tr><td class="pwdCapsBorder"><img src="/html/themes/asite/images/common/caps_msg_arrow.gif" hspace="10" /></td></tr><tr><td class="pwdCapsMsg"> Caps Lock is on.</td></tr></table></span>
</td>
</tr>
</table>
<div class="div-submit"> </div>
<div class="div-login-link">
<input class="btn-submit nobgcolor" type="image" src="/html/themes/asite/images/common/login.gif" />
<a target="_self" href="https://portal.asite.com/widget/web/guest/home?p_p_id=58&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&_58_struts_action=%2Flogin%2Fview&_58_cmd=forgot-password">Forgot Password?</a>
<br/>
<a href="https://www.asite.com/contactus" target="_top">Don't have an account?</a>
<br/>
<div class="clear-all"></div>
<div class="clear-all"></div>
</div>
</form>
<script type="text/javascript">
【问题讨论】:
-
你试过.InnerText吗?
-
真正的问题是什么?
标签: excel vba internet-explorer-11