使用Excel VBA切换到Web iframe,然后填写下拉词



我的代码下方打开网页,调用java-script函数。我想要的是:切换到名为displayFrame的iframe。然后在下拉阶段中选择选项。目前,我无法切换到iframe,并以表单添加值。我是新手,所以需要您的帮助。

代码:

Option Explicit
Sub Fillform()
Dim URL As String
Dim ie, frm As Object
Dim FF As Integer
Dim wb As WebBrowser
Dim objElement As Object
Dim objCollection As Object
Dim button, goBtn As Object
Dim HTML As HTMLDocument
Dim Dropdown As IHTMLElement
Dim dropOption As IHTMLElement
Dim HTMLdoc As HTMLDocument
Dim link As HTMLLinkElement
Dim theFrame As HTMLIFrame
Dim Frame1, Frame2 As HTMLIFrame
On Error Resume Next
Application.ScreenUpdating = False
URL = "https://webtac.industrysoftware.automation.siemens.com/webpr/webpr.php?objtype=frames&g_userid=a3rgcw&g_session_id=7302840" 'for TEST
Set ie = CreateObject("Internetexplorer.Application")
ie.Visible = True
ie.Navigate URL
Do Until ie.ReadyState = 4
DoEvents
Loop
' Call java-script function
ie.Navigate ("javascript:parent.gotoCreate('advanced');")
Do Until ie.ReadyState = 4
DoEvents
Loop
Set theFrame = HTMLdoc.frames(0)
Set HTML = ie.Document
ie.Document.all.Item("product_application").Value = "NX"
ie.Document.getElementById("textInputField").Value = "N/A"
Set Dropdown = HTML.getElementById("product_application")
    For Each dropOption In Dropdown.getElementsByTagName("option")
        If dropOption.innerText = "Design" Then
            Dropdown.Value = dropOption.Value
            Exit For
        End If
    Next dropOption
' or may be this way to select drop-down
ie.Document.getElementById("priority_selection").Value = "Design"

iframe html代码:

<frame name="displayFrame" src="/webpr/webpr.php?objtype=MyWebPR&amp;g_userid=a3rgcw&amp;g_session_id=7321635&amp;g_devmode=&amp;g_dbname=">

如何获取iframe文档的提示 - 尝试遵循此逻辑(未测试)

'for early binding
Dim IEApp As InternetExplorer
Set IEApp = New InternetExplorer
Dim docHTML As HTMLDocument
Set docHTML = IEApp.document
Dim webIFrame As Object 'As HTMLIFrame
'try with any of this lines to get to IFrame
Set webIFrame = docHTML.getElementsByTagName("iframe")(0) 'your index if not 0
Set webIFrame = = docHTML.frames(0)
'and to get to document:
Dim docIFrameHTML As HTMLDocument
set docIFrameHTML = webIFrame.document
'next you could try to fill your forms...

相关内容

最新更新