vba 用sendmessage如何点击网页弹出对话框的保存按钮 求大大帮忙,急!!!

Private Declare Function FindWindow Lib "USER32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function FindWindowEx Lib "USER32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPrivate Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const BM_CLICK = &HF5

Sub aa()Dim hwd As Long, hwd_child As Longhwd = FindWindow("#32770", "文件下载 - 安全警告") '网页对话框的句柄hwd_child = FindWindowEx(hwd, 0, "button", "保存(&S)") ‘保存按钮的句柄SendMessage hwd_child, BM_CLICK, 0, 0 '发送鼠标单击End Sub
这是网上下载软件弹出来的网页对话框,hwd 和hwd_child都能找到,但是就是点不了保存按钮,如果焦点在取消按钮上,这段代码只会把焦点放到保存按钮上来,而不会点下去,怎么回事?如图:

确定hwd 和hwd_child都能找到?如果都能找到的话,是SENDMESSAGE失效了,不知道为什么,有的时候SENDMESSAGE会失效。
如果要下载某网页文件的话,推荐以下代码,文件链接可以通过internetexplorer.application的方法找到,或者你告诉我原网页在哪
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Declare Function DeleteUrlCacheEntry Lib "wininet" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Sub test()
Dim nUrl As String, localFilename As String, lngRetVal As Long
nUrl = "http://www.baidu.com/img/baidu_logo.gif" '要下载的文件链接
localFilename = ThisWorkbook.Path & Application.PathSeparator & "myimg.gif" '保存到本地的完整路径
DeleteUrlCacheEntry nUrl '清除缓存
lngRetVal = URLDownloadToFile(0, nUrl, localFilename, 0, 0)
If lngRetVal = 0 Then
MsgBox "成功"
Else
MsgBox "失败"
End If
End Sub追问

如何获得文件链接?我只有一个地址url1,这个地址不是以文件名结尾,设置document.location.href=url1以后下载框就弹出来了

温馨提示:内容为网友见解,仅供参考
无其他回答

Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答