IE在Excel宏中处理 [英] IE Handling in Excel macros
本文介绍了IE在Excel宏中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Excel宏的新手,我试图自动填充文本框,然后从下拉菜单中选择选项,然后单击提交.
I am new to Excel macros and I am trying to auto-fill the text box and select the option from Dropdown and click on Submit.
使用我导航到页面的宏,然后从该页面中,我需要在文本框中输入文本,然后根据建议"选择选项.
Using macros I have navigated to a page and from the page, I need to enter the text in the text box, and based on the Suggestion, I need to select the option.
选择该选项后,我需要单击继续使用宏".
Once the option is selected I need to click on continue using macros.
这是当前代码(我尝试使用带注释的行,但不起作用).
Here is the current code (I tried with the commented line but it's not working).
Sub Create_Change()
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
URL = "URL to Navigate"
IE.Navigate URL
Application.StatusBar = URL & " is loading. Please wait..."
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
Application.StatusBar = URL & " Loaded"
' IE.Document.All("Search for a template").Value = "text to search"
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
HTML代码:
<input title="Search for a template"
class="change-template__search-input ng-pristine ng-untouched ng-valid"
role="combobox"
aria-expanded="false"
aria-owns="typeahead-258-8737"
aria-autocomplete="list"
type="text"
placeholder="Search for a template"
ng-enter="getRecommendedTemplates(template.search)"
ng-model="template.search"
typeahead="template as template for template in getTemplateList($viewValue)"
typeahead-focus-first="false"
typeahead-on-select="getRecommendedTemplates($item)"
typeahead-min-length="3">
推荐答案
您可以尝试以下操作:
1)专注并改变
With ie.document.querySelector("[title='Search for a template']")
.focus
.value = "abcd"
End With
2)Javascript设置值
2) Javascript set value
ie.document.parentWindow.execScript "document.querySelector('[title=\'Search for a template\']').value = 'abcd';"
3)附加事件并触发
Dim evt As Object
Set evt = ie.document.createEvent("HTMLEvents")
evt.initEvent "change", True, False
With ie.document.querySelector("[title='Search for a template']")
.Focus
.Value = "abcd"
.dispatchEvent evt
End With
4)FireEvent
4) FireEvent
With ie.document.querySelector("[title='Search for a template']")
.Focus
.Value = "abcd"
.FireEvent "onchange"
End With
这篇关于IE在Excel宏中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文