gpt4 book ai didi

VBA 在 Win7x64 中单击 IE11 另存为对话框

转载 作者:行者123 更新时间:2023-12-04 20:30:45 34 4
gpt4 key购买 nike

我正在尝试让 VBA 自动从 IE 保存文件。感谢这些论坛上的各种帖子,我可以登录、浏览页面并单击下载链接。保存提示出现在IE的底部,然后我就卡住了:

IE11 Save Dialogue

我一直在尝试使用 https://www.mrexcel.com/forum/excel-questions/502298-need-help-regarding-ie-automation-using-vba-post3272730.html#post3272730 中的代码示例,但第二个 FindWindow 总是返回 0:

hWnd = FindWindowEx(hWnd, 0, "DUIViewWndClassName", vbNullString) 

我在 Excel 14 和 IE11 中使用 VBA 7.0。

原帖顶部有建议:

'Note - IE may block the download, displaying its Information Bar at the top of the tab, and preventing this program from 'automatically downloading the file. To prevent this, add NRLDC to IE's Trusted sites (Tools - Internet Options - 'Security - Trusted sites - Sites)



由于 IT 政策,我无法访问受信任的站点列表,但出现下载提示,所以我认为这不是问题。

我获取的代码来自 Doongiereply ,这表明它已针对 Windows 7 进行了更新:
Private Sub File_Download_Click_Save()

Dim hWnd As Long
Dim timeout As Date

Debug.Print "File_Download_Click_Save"

'Find the File Download window, waiting a maximum of 30 seconds for it to appear

timeout = Now + TimeValue("00:00:30")
Do
hWnd = FindWindow("#32770", "") 'returns various numbers on different runs: 20001h 10440h
DoEvents
Sleep 200
Loop Until hWnd Or Now > timeout

Debug.Print " File Download window "; Hex(hWnd)

If hWnd Then
SetForegroundWindow hWnd

'Find the child DUIViewWndClassName window
hWnd = FindWindowEx(hWnd, 0, "DUIViewWndClassName", vbNullString) 'always returns 0
Debug.Print " DUIViewWndClassName "; Hex(hWnd)
End If

If hWnd Then
'Find the child DirectUIHWND window
hWnd = FindWindowEx(hWnd, 0, "DirectUIHWND", "")
Debug.Print " DirectUIHWND "; Hex(hWnd)
End If

If hWnd Then
'Find the child FloatNotifySink window
hWnd = FindWindowEx(hWnd, 0, "FloatNotifySink", "")
Debug.Print " FloatNotifySink "; Hex(hWnd)
End If

If hWnd Then
'Find the child ComboBox window
hWnd = FindWindowEx(hWnd, 0, "ComboBox", "")
Debug.Print " ComboBox "; Hex(hWnd)
End If

If hWnd Then
SetForegroundWindow hWnd

'Find the child Edit window
hWnd = FindWindowEx(hWnd, 0, "Edit", "")
Debug.Print " Edit "; Hex(hWnd)
End If

If hWnd Then
'Click the Save button
SetForegroundWindow hWnd
Sleep 600 'this sleep is required and 600 milliseconds seems to be the minimum that works
SendMessage hWnd, BM_CLICK, 0, 0
End If

End Sub

有什么方法(不会让我在 IT 方面遇到麻烦!)我可以检查 IE 元素的句柄编号吗?代码检查器只显示页面代码,而不是 IE 对话框。

是否有 lpsz1 的可能元素名称列表?在某处定义,因为它们适用于 IE 的元素?
Public 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

最佳答案

你试过可怕的发送键吗?

Application.SendKeys "%{S}"
Application.SendKeys "%{O}"

关于VBA 在 Win7x64 中单击 IE11 另存为对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421388/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com