Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save file from Webpage from Excel VBA?

I am trying to export a file from IE, after selecting an item in dropdown by taking the Html ID and clicking the export option, but i am strucked while saving the file.
I am Selecting the option in the dropdown based on the value in an excel range.

Please help.
Below is the code I am trying.

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 snap shot I am strucked here, and here i want to save the file.
how to select Save

like image 910
Punith GP Avatar asked Nov 01 '22 03:11

Punith GP


1 Answers

Add the following in your code:

Dim Report As Variant

Report = Application.GetSaveAsFilename("Attrition Report.xls", "Excel Files (*.xls), *.xls")
like image 104
ktk Avatar answered Nov 08 '22 05:11

ktk