IE11框架通知栏 - 单击"保存"

时间:2016-06-10 17:02:58

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

我陷入了自动化过程中我需要访问IE11中的帧通知栏的一点 - 我发现下面的代码很有用,但是接收到了#34; Type Mismatch"在线

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

1 个答案:

答案 0 :(得分:0)

在导航

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

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

替换

Dim ie As SHDocVw.InternetExplorer
Set ie = New InternetExplorerMedium

  Dim ie As Object

  Set ie = CreateObject("InternetExplorer.Application")