我被困在一个需要访问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发布于 2016-06-11 01:30:39
在导航后立即执行此操作时,我没有收到任何错误
第一步是编译它--可能在你来这里之前先试试这个
替换
Dim ie As SHDocVw.InternetExplorer
Set ie = New InternetExplorerMedium使用
Dim ie As Object在此之前
Set ie = CreateObject("InternetExplorer.Application")https://stackoverflow.com/questions/37753630
复制相似问题