1

我正在尝试通过 Windows API 从 Excel 的 VBA 更改 Google Chrome 下载窗口中的保存路径。即下面屏幕截图中标记为“temp”的部分需要在单击“保存”按钮之前进行更新。

在此处输入图像描述

我可以使用下面的代码找到它所在的工具栏而没有问题。

downloadWindow = FindWindow(vbNullString, "Save As")
subWindow = FindWindowEx(downloadWindow, ByVal 0&, "WorkerW", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "ReBarWindow32", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "Address Band Root", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "msctls_progress32", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "Breadcrumb Parent", vbNullString)
savePath = FindWindowEx(subWindow, ByVal 0&, "ToolbarWindow32", vbNullString)

问题在于更新路径。我试过用下面的 SendMessage 命令来做,但这不起作用。

SendMessageByString savePath, WM_SETTEXT, 0, "C:\newpath"

如何更新路径?

4

1 回答 1

1

我整天都在尝试解决同样的问题,我刚刚发现您不需要更改工具栏路径。您可以将完整的文件路径设置到文件名框中,它将保存到所需的位置。

downloadWindow = FindWindow(vbNullString, "Save As")
subWindow = FindWindowEx(downloadWindow, ByVal 0&, "DUIViewWndClassName", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "DirectUIHWND", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "FloatNotifySink", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "ComboBox", vbNullString)
subWindow = FindWindowEx(subWindow, ByVal 0&, "Edit", vbNullString)

Dim FullPath As String
FullPath = "C:\myfolder\myfile.xyz"
Call SendMessage(subWindow, WM_SETTEXT, False, ByVal FullPath )

如果您还没有这样做,则需要包含 Sendmessage 函数和 FindWindowEx 函数

Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
于 2019-02-22T14:47:06.203 回答