How to save a file from a web page from Excel VBA?

I am trying to export a file from IE, after selecting an item from the drop-down list, taking the HTML identifier and clicking the export option, but I hit when saving the file.
I select an option from the drop-down list based on the value in the excel range.

Please, help.
Below is the code I'm trying to do.

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    

And the picture was taken by me, and here I want to save the file.
how to select Save

+4
source share
2 answers

Add the following to your code:

Dim Report As Variant

Report = Application.GetSaveAsFilename("Attrition Report.xls", "Excel Files (*.xls), *.xls")
+2
source

I sent keyboard shortcuts to click the save button in IE11.

: , , IE , .

  • : Alt + S
  • VBA: Application.SendKeys "%{S}"
0

Source: https://habr.com/ru/post/1532247/


All Articles