|
本帖最后由 南宫煌sea 于 2014-6-3 18:47 编辑
EH各位老师好,我用VBA写了将Excel数据填写到网页表单上,但是提交的时候会弹出来自网页信息的窗口,需要按确定才能继续下一步。我在EH上查找了弹出来自网页信息的窗口的相关帖,用蓝天老师写的代码单独可以运行,但是放到提交代码后,却不能按确定窗口,liucqa老师说这是VBA单线程的原因造成的,需要用API处理,请问EH各位老师有没有一些例子提供给我参考一下,或者有没有其他的处理方法呢?
附上写的代码:
- Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
- Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
- Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
- Private Const WM_LBUTTONDOWN = &H201
- Private Const WM_LBUTTONUP = &H202
- Private Const MK_LBUTTON = &H1
- Sub Execl填写网页表单()
- Dim mShellwindows As New ShellWindows, ie As InternetExplorer
- For Each ie In mShellwindows
- If ie.LocationURL Like "http://10.3.18.72/enq/inqueryAction.do?reqCode=inqRegBegin&enqSort=INQ_DOM&inoutFlag=OUT&enqClass=1&srcTab=1*" Then Exit For
- Next
- With ie.Document
- .all("itemno").Value = Cells(2, 1)
- .all("collTime").Value = Cells(2, 2)
- .all("collDstAlphaid").Focus
- .all("collDstAlphaid").Value = Cells(2, 3)
- t1 = Timer
- Do Until Timer > t1 + 3 '需要时间触发网页上的onblur函数
- Loop
- .all("senderName").Value = Cells(2, 4)
- .all("senderPhone").Value = Cells(2, 5)
- .all("senderAddr").Value = Cells(2, 6)
- .all("recverName").Value = Cells(2, 7)
- .all("recverPhone").Value = Cells(2, 8)
- .all("recverAddr").Value = Cells(2, 9)
- .all("explain").Focus
- .all("explain").Value = Cells(2, 10)
- Do Until Timer > t1 + 5 '等待关联菜单显示内容
- Loop
- .all("btnSend").Click 'click之后会弹出一个确定的对话框,之前试过submit Form,不过这里不行
- End With
-
- winHwnd = FindWindow(vbNullString, "来自网页的消息") '这段代码是在EH上看到蓝天老师写的,单独运行可以,放在这里运行不行
- If winHwnd <> 0 Then
- btnHwnd = FindWindowEx(winHwnd, 0, "Button", "确定")
- SendMessage btnHwnd, WM_LBUTTONDOWN, 0, ByVal 0
- SendMessage btnHwnd, WM_LBUTTONUP, 0, ByVal 0
- SendMessage btnHwnd, WM_LBUTTONDOWN, 0, ByVal 0
- SendMessage btnHwnd, WM_LBUTTONUP, 0, ByVal 0
- End If
-
- Do While ie.Busy
- DoEvents
- Loop
-
-
- End Sub
复制代码 |
|