使用VBA excel在iFrame中单击下拉选项

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用VBA excel在iFrame中单击下拉选项相关的知识,希望对你有一定的参考价值。

我正在尝试在下面的代码中单击下拉选项“批准交易”。我有扎实的VBA背景知识,但这是我第一次尝试使用VBA excel实现html自动化。到目前为止,我已经能够导航并登录到网站,选择需要批准的交易,并显示下拉列表。但是,我不知道如何单击下拉选项/触发事件。我相信我的差距正在处理iFrame和/或表格(到目前为止,我在代码中不必处理的事情)

我已经测试了很多不同的网络发现代码,因此我不会反悔我曾经遇到的每份复制/粘贴修改过的故障。下面是我尝试与之交互的代码。我正在尝试点击/触发“批准交易”。

感谢您提供任何建议!

经过编辑,在下面包含HTML和我的代码。我一直在删除无法正常工作的东西,只是插入并播放其他选项。我确定的那篇作品可能非常错误。

    <IFRAME id=VCommonBlockerVxActionMenu_68_SUPPORT style="BORDER-TOP: 0px; HEIGHT: 62px; BORDER-RIGHT: 0px; WIDTH: 98px; BORDER-BOTTOM: 0px; POSITION: absolute; LEFT: 1402px; FILTER: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0); BORDER-LEFT: 0px; Z-INDEX: 12; DISPLAY: block; TOP: 98px; BACKGROUND-COLOR: #ffffff; 0: " src="javascript:false" frameBorder=0 scroll="no"></IFRAME>

<DIV id=VxActionMenu_68_SUPPORT class=VDropDown_support style="HEIGHT: 62px; WIDTH: 98px; LEFT: 1402px; Z-INDEX: 13; DISPLAY: inline; TOP: 98px"><TABLE id=VxActionMenu_68_OPTIONS class=VDropDown_options style="WIDTH: 100%" cellSpacing=0 cellPadding=0 border=0>
<COLGROUP>
<COL width=22></COL>
<COL width="100%"></COL>
<COL width=22></COL>
<TBODY>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class="VDropDown_hiderow VDropDown_option" vvalue="null">
<TD class=VDropDown_leftimg>&nbsp;</TD>
<TD class=VDropDown_option>More Actions</TD>
<TD class=VDropDown_rightimg>&nbsp;</TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class="VDropDown_option VDropDown_select" vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Approve',{statusMsg: 'Approving...'}, {vx_wsid: 'WS3',okHandler:'vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Approve',showDialog:'true',statusMsg:'Approving...'});">
<TD title="Approve the Deal" class=VDropDown_option colSpan=2><NOBR>Approve</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class=VDropDown_option vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Deny',{statusMsg: 'Denying...'}, {vx_wsid: 'WS3',okHandler:'vx.actions.VxAgreement_CommitHandler,vx.actions.VxApprovable_Deny',showDialog:'true',statusMsg:'Denying...'});">
<TD title="Deny the Deal" class=VDropDown_option colSpan=2><NOBR>Deny</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR>
<TR onmouseover=VPage.VxActionMenu_68.hilite(event); onmousedown=VPage.VxActionMenu_68.select(event); class=VDropDown_option vfixed="true" vupdateLabel="true" vjs="VxManager.invokeActionHandler('vx.publishing.VxPublishingDocActions_OpenOrNew',{statusMsg: 'Publishing...'}, {vx_wsid: 'WS3'});">
<TD title="Create a document from the deal" class=VDropDown_option colSpan=2><NOBR>Publish</NOBR></TD>
<TD class=VDropDown_rightimg><IMG src="http://venprd.na.odcorp.net/vendavo/images/icons/clear.gif" width=16 align=absBottom height=1></IMG></TD></TR></TBODY></TABLE></DIV>

我还有另一个工作组来导航到网站并登录。

Sub VendavoApprove()
    Dim elmButton As MSHTML.IHTMLElement

    'Activate previously opened Vendavo page
    'Set shellWins = New SHDocVw.ShellWindows

    'For Each explorer In shellWins
    'If explorer.Name = "Internet Explorer" Then
    'Debug.Print explorer.LocationURL
    'Debug.Print explorer.LocationName
    'End If
    'Next

    'Set shellWins = Nothing
    'Set explorer = Nothing

    AppTitle = "Powered by Vendavo"

    AppActivate AppTitle

    Set oApp = CreateObject("Shell.Application")

    For i = 0 To 25

        strName = ""

        On Error Resume Next

        strName = oApp.Windows(i).document.URL

        If InStr(strName, "http://venprd.na.odcorp.net/vendavo/pc?page=vx.core.BasicPage&menuId=deals&folderId=quotes") Then

            Set oIE = oApp.Windows(i)

            Exit For

        End If

    Next

    oIE.Visible = True

    oIE.document.all("VTree_VxFolderNav_deals.13.icon").Click
    oIE.document.all("table_VxCanvasListing_inner_1_COL_1_FILTER").Click
    oIE.document.all("table_VxCanvasListing_inner_COL_1_FILTER").Click
    oIE.document.all("table_VxCanvasListing_inner_1_FILTER_VALUE1").Value = 9792365
    oIE.document.all("table_VxCanvasListing_inner_FILTER_VALUE1").Value = 9792365
    oIE.document.all("id1_label").Click
    oIE.document.all("table_VxCanvasListing_inner_1$x0_ROWHDR").Click
    'oIE.document.all("table_VxCanvasListing_inner_1_ActionMenus_LABEL").Click
    oIE.document.all("table_VxCanvasListing_inner_1$x0_1").FireEvent "ondblclick", 1, 2
    oIE.document.all("table_VxCanvasListing_inner$x0_1").FireEvent "ondblclick", 1, 2
    oIE.document.getElementById("VxActionMenu_68_LABEL").Click 'Dynamic
    oIE.document.getElementById("VxActionMenu_67_LABEL").Click 'Dynamic
    oIE.document.getElementById("VxActionMenu_237_LABEL").Click 'Dynamic
    'Approve the core - this is the part I'm working on
    Set htm = oIE.document.frames("VCommonBlockerVxActionMenu_68_SUPPORT").document
    Set frms = htm.forms("TargetForm")
    Set Class1 = frms.document.getElementsByTagName("VxActionMenu_68_OPTIONS")

    For Each inputelement In Class1
        If inputelement.getAttribute("title") = "Approve the Deal" Then
            inputelement.Click
            Exit For
        End If
    Next
    'ending here
    oIE.document.all("VxApprovableComments_71_COMMENT").Value = "Approved"
    oIE.document.all("id1_label").Click

End Sub
答案

好像tr在iframe外部,并且具有mousedown事件,您可以尝试附加和触发。我的目标是tr的vjs属性。

Dim evt As Object
Set evt = .document.createEvent("HTMLEvents")
evt.initEvent "mousedown", True, False

oIE.document.querySelector("[vjs*=VxApprovable_Approve]").dispatchEvent evt

以上是关于使用VBA excel在iFrame中单击下拉选项的主要内容,如果未能解决你的问题,请参考以下文章

VBA代码根据excel工作簿中的值从webform下拉列表中选择一个值

在excel表格中怎么设置双击之后填自动填充颜色?

Excel VBA在IE11中使用自动完成填充文本框

如何在EXCEL中练习VBA?

Excel 如何实现五级下拉菜单联动

如何隐藏 excel 表单