【问题标题】:How to save file from Webpage from Excel VBA?如何从 Excel VBA 保存网页中的文件?
【发布时间】:2014-04-23 14:50:21
【问题描述】:

在通过获取 Html ID 并单击导出选项在下拉列表中选择一个项目后,我试图从 IE 导出文件,但是在保存文件时我被击中了。
我正在根据 excel 范围内的值选择下拉列表中的选项。

请帮忙。
下面是我正在尝试的代码。

Dim htm As Object
Dim IE As Object
Sub Website()

    Dim Doc As Object
    Set IE = CreateObject("internetexplorer.application")
    IE.Visible = True

    IE.navigate "http://**Link is confidential, sorry for not providing link**"

    Do While IE.readystate <> 4: DoEvents: Loop

    Set Doc = CreateObject("htmlfile")
    Set Doc = IE.document

        Set ref = Doc.getelementbyid("ReportViewerControl_ctl01_ctl05_ctl00")
        For x = 0 To ref.Options.Length - 1
            If ref.Options(x).Text = "Excel" Then
                ref.selectedIndex = x
                Set refclick = Doc.getelementbyid("ReportViewerControl_ctl01_ctl05_ctl01")
                refclick.Click
                Set refclick = Nothing
            End If
        Next
    Set IE = Nothing
End Sub    

还有快照我在这里被打动了,我想在这里保存文件。

【问题讨论】:

标签: internet-explorer excel save excel-2007 vba


【解决方案1】:

我发送的快捷键是点击IE11中的保存按钮。

注意:如果 IE 不是您机器上的活动窗口,则代码将不会按您的预期运行,因此在调试模式下将无法运行。

  • 快捷键:Alt+S
  • VBA:Application.SendKeys "%{S}"

【讨论】:

    【解决方案2】:

    在您的代码中添加以下内容:

    Dim Report As Variant
    
    Report = Application.GetSaveAsFilename("Attrition Report.xls", "Excel Files (*.xls), *.xls")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-24
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 1970-01-01
      相关资源
      最近更新 更多