导入 csv 时遇到问题。来自下载链接的文件

时间:2021-06-16 19:37:20

标签: excel vba csv internet-explorer download

我正在尝试自动化 csv。从 IE 链接下载。 我设法打开了网络浏览器,但出现了一个弹出窗口,要求选择“保存”“打开”。 我无法做的是使用 VB 命令单击“保存”按钮。尝试使用 SendKeys 这样做,但它不起作用。在寻找解决方案时,我发现它可能与聚焦弹出窗口有关,我也尝试过,但没有成功。

这是我到目前为止所做的:(此脚本在模块中)

Option Explicit

Public Sub NavigateToURL(ByVal argURL As String)

On Error Resume Next

    Const READYSTATE_COMPLETE As Integer = 4

    Dim objIE As Object
    Set objIE = CreateObject("InternetExplorer.Application")

    With objIE
      .Visible = True
      .Silent = True
      .navigate argURL
      Do Until .readyState = READYSTATE_COMPLETE
        DoEvents
     Loop
   End With

   ''Application.SendKeys "{TAB}", True

   objIE.Quit
   Set objIE = Nothing

 End Sub

这是在运行脚本的 ActiveX 命令按钮中:

Private Sub cmdARKK_Click()

  Call NavigateToURL("https://etfdb.com/holdings-export/2062/")
  Application.Wait (Now + TimeValue("0:00:05"))   '''for the browser to start
  Application.SendKeys "{TAB}", True    '''just a test to try and see if the popup window reacts to the command    

End Sub

注意:该网站的下载链接仅适用于高级用户。

欢迎任何建议。如果有人可以帮助解决 SendKeys,那将非常适合我项目的其余部分。 感谢帮助者!

0 个答案:

没有答案