2

To do so, I wrote the following VBA script and bound it a button which sets some parameters and loads the data. Afterwards it removes the connection to avoid a pile of stale connections.

Private Sub LoadData_Click()
    Dim ConnString As String
    Dim URL As String
    URL = "https://some-server/some/path/some-file.csv"
    ConnString = "TEXT;" + URL + "?partner_code=" + CStr(Range("B2")) + "&from=" + CStr(Range("B3")) + "&to=" + CStr(Range("B4"))

    Sheets("Import").Select
    Sheets("Import").UsedRange.Clear
    ActiveSheet.Range("A1").Value = "Data is being loaded. Hold on..."
    With ActiveSheet.QueryTables.Add(Connection:=ConnString, Destination:=ActiveSheet.Range("A1"))
        .Name = _
        " "
        .FieldNames = True
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlOverwriteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFilePlatform = xlWindows
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = False
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1)
        .TextFileDecimalSeparator = ","
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With

   Do While ActiveWorkbook.Connections.Count > 0
      ActiveWorkbook.Connections.Item(ActiveWorkbook.Connections.Count).Delete
   Loop

    Sheets("Parameter").Select
End Sub

It works fine with Excel 2010, but not with 2013. When clicking my button I'm prompted for credentials and enter them. With Excel 2010 I see on server side in apache logs some superfluous OPTIONS requests and a HEAD, but finally just one GET which pulls the data.

With Excel 2013 I see three OPTIONS, then a HEAD which is successful (200) and finally a GET which is not successful (401). To further investigate it I did activate mod_dumpio module to see what's happening. And Apache is of course right to turn down excel 2013:

HEAD /some/path/some-file.csv?partner_code=25010&from=01.01.2014&to=01.06.2014 HTTP/1.1\r\n
...
Authorization: Basic Y29udHJvbGxpbmc6Rm9vNWFoUGg=\r\n

which is responded with 200 and directly afterwards a GET appears

GET /some/path/some-file.csv?partner_code=25010&from=01.01.2014&to=01.06.2014 HTTP/1.1\r\n

which lacks the basic auth header and therefore is answered by

HTTP/1.1 401 Unauthorized\r\nDate: Thu, 03 Jul 2014 18:18:59 GMT\r\nServer: Apache\r\nPragma: No-cache\r\nCache-Control: no-cache\r\nExpires: Thu, 01 Jan 1970 01:00:00 CET\r\nWWW-Authenticate: Basic realm="Import/Export"\r\nVary: Accept-Encoding\r\nContent-Encoding: gzip\r\nContent-Length: 378\r\nConnection: close\r\nContent-Type: text/html;charset=utf-8\r\n\r\n

I was following instructions in http://support.microsoft.com/kb/2123563/en-us step by step, but it did not help. Also the HEAD is actually working and using Basic auth.

How to load CSV data into Excel 2013 using https with basic authentication?

Gerrit Griebel
  • 405
  • 3
  • 10

0 Answers0