【问题标题】:IE11 Frame Notification Bar - Click "Save"IE11 框架通知栏 - 点击“保存”
【发布时间】:2016-06-11 02:15:19
【问题描述】:

我在自动化过程中遇到了困难,我需要访问 IE11 中的框架通知栏 - 我发现下面的代码很有用,但在线上收到“类型不匹配”

h = ie.Hwnd

是因为我已将 IE 声明为 internetexplorermedium 吗?

Option Explicit

Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long

Sub lime()
Application.DisplayAlerts = False
Dim ie As SHDocVw.InternetExplorer
Dim doc As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
Set ie = New InternetExplorerMedium
ie.Visible = True
ie.Navigate ("http://xxx/")
Doodly ie
Muddly ie
Set doc = ie.Document

doc.getElementById("ctl32_ctl04_ctl03_ddValue").Value = "4"

doc.parentWindow.execScript "__doPostBack('ctl32$ctl04$ctl03$ddValue','')", "JavaScript"

Application.Wait (Now() + TimeValue("00:00:05"))

doc.getElementById("ctl32_ctl04_ctl05_ddValue").Value = "1"

doc.getElementById("ctl32_ctl04_ctl00").Click

Application.Wait (Now() + TimeValue("00:00:05"))

doc.parentWindow.execScript "$find('ctl32').exportReport('EXCELOPENXML')", "JavaScript"

Application.Wait (Now() + TimeValue("00:00:05"))


Dim o As IUIAutomation
Dim e As IUIAutomationElement
Set o = New CUIAutomation
Dim h As Long
h = ie.Hwnd
h = FindWindowEx(h, 0, "Frame Notification Bar", vbNullString)
If h = 0 Then Exit Sub

Set e = o.ElementFromHandle(ByVal h)
Dim iCnd As IUIAutomationCondition
Set iCnd = o.CreatePropertyCondition(UIA_NamePropertyId, "Save")

Dim Button As IUIAutomationElement
Set Button = e.FindFirst(TreeScope_Subtree, iCnd)
Dim InvokePattern As IUIAutomationInvokePattern
Set InvokePattern = Button.GetCurrentPattern(UIA_InvokePatternId)
InvokePattern.Invoke

End Sub

Sub Doodly(ie)
Do
    DoEvents
Loop Until ie.readystate = 4
End Sub

Sub Muddly(ie)
Do While ie.busy
    DoEvents
Loop
End Sub

【问题讨论】:

    标签: excel vba notifications frame internet-explorer-11


    【解决方案1】:

    在导航后立即执行此操作时没有错误

    第一步是编译它——可能在你来这里之前 试试这个

    替换

    Dim ie As SHDocVw.InternetExplorer
    Set ie = New InternetExplorerMedium
    

      Dim ie As Object
    

    之前

      Set ie = CreateObject("InternetExplorer.Application")
    

    【讨论】:

    • 项目无法编译,我在“h = ie.Hwnd”行收到“类型不匹配”错误,是我缺少参考还是什么? excel 2010
    • 您是否手动输入了Dim ie As SHDocVw.InternetExplorer - 还是 IntelliSense 在您输入时开始为您提供 SHDoc 关键字?
    • 可能解释了为什么它不能编译——用初步建议更新了我的答案
    • 谢谢,但我正在访问一个 Intranet 站点,并且根据之前的研究,我需要“Set ie = New InternetExplorerMedium”才能使代码正常工作。我的代码一直有效,直到出现框架通知栏,直到“Dim o As IUIAutomation”开始。任何其他想法,或者它不能与我定义的方式一起使用吗?
    • 好吧。您将 ie 定义为多个引用并覆盖以前的定义 - 如果您需要多个定义,则将它们定义为多个对象。您基本上是在覆盖您最初将它们设置为的内容。现在错误在Dim i as IUIAutomation??
    猜你喜欢
    • 2015-10-07
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多