Results 1 to 8 of 8

Thread: How can VBA fill-in web form??

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #5
    VBAX Regular
    Joined
    Jul 2008
    Location
    Cincinnati, OH
    Posts
    86
    Location
    Hi Dave. You can download your file directly from the server without using IE. The code below may or may not work because I am only guessing what the request header may be. If it does not work, let me know and we'll try a variation. There are also three other parameters that are not user-defined.

    action=U
    mode=R
    app=swr

    These are probably always the same but they may not be.

    It is not neccesary to use all of the variables in the ExampleUsage procedure or the enum. I placed them there for readability.

    Private Enum OutputFormat
        HtmlOnline = 1
       ExcelCSV = 2
        PDF = 4
    End Enum
    
    Sub ExampleUsage()
        Dim URL As String
        Dim ReportId As String
        Dim OutPutType As OutputFormat
        Dim EarliestClosedDate As String
        Dim LatestClosedDate As String
        Dim SaveToLocalFile As String
        URL = "http://intranet.urlhere.com/cgi/swr/swr_run.pl?"
        ReportId = "8541"
        OutPutType = ExcelCSV
        EarliestClosedDate = "01-Dec-2008"
        LatestClosedDate = "31-Dec-2008"
        SaveToLocalFile = "C:\Documents and Settings\dk\Desktop\2008.06_data_feed_TEST.xls"
        Call GetFileFromServer(URL, ReportId, OutPutType, EarliestClosedDate, LatestClosedDate, SaveToLocalFile)
    End Sub
    
    Sub GetFileFromServer(URL As String, _
        ReportId As String, OutPutType As OutputFormat, _
        EarliestClosedDate As String, LatestClosedDate As String, _
        SaveToLocalFile As String)
        Dim Request As Object
        Dim FileNum As Integer
        Dim b() As Byte
        On Error Resume Next
        Set Request = CreateObject("WinHttp.WinHttpRequest.5.1")
        If Request Is Nothing Then
            Set Request = CreateObject("WinHttp.WinHttpRequest.5")
        End If
        On Error GoTo 0
        With Request
            .Open "GET", URL, False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .Send "report=" & ReportId & "&action=U&mode=R&app=swr&outputType=" & OutPutType & _
            "&parameter_1=" & EarliestClosedDate & "&parameter_2=" & LatestClosedDate
        End With
        FileNum = FreeFile
        Open SaveToLocalFile For Binary As #FileNum
        b() = Request.ResponseBody
        Put #FileNum, 1, b()
        Close FileNum
    End Sub
    Last edited by Aussiebear; 04-12-2025 at 04:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •