Excel VBA从下载对话框打开文件

在这里需要帮助,试图使用VBA与下载对话框进行交互。

不幸的是无法发布的图像,因为我没有要求的声誉这样做。

但它只是一个简单的对话框,只有3个选项。

1)打开2)另存为3)保存

我想要做的是,而不是窗口/ Excel提示对话框,Excel VBA将直接打开它。 任何人都知道? (SendKeys“{TAB}”,True / SendKeys“{ENTER}”,True),但没有发生任何事情。

你可以试试这个,因为它是在IE9上为我工作的:

下面显示下载

  1. 将文件C:\Windows\System32\UIAutomationCore.dll文件复制到用户文档即C:\Users\admin\Documents然后将参考UIAutomationClient添加到您的macros文件。
  2. 将以下代码粘贴到您的模块中:

      Option Explicit Dim ie As InternetExplorer Dim h As LongPtr Private Declare PtrSafe Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As LongPtr, ByVal hWnd2 As LongPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPtr Sub Download() Dim o As IUIAutomation Dim e As IUIAutomationElement Set o = New CUIAutomation 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 

试试你的结局。