Hello all,
I'm getting "Invalid Query" on .Refresh BackgroundQuery:=False when stepping through the code. Is there a way to import .xls files from the web using querytables? I've seen it done for .csv and I'm trying to adapt that code to xls.
Thank you for helping!
Sub XLSImport()
Dim ImportSht As Worksheet
Set ImportSht = Sheet6
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
ImportSht.Cells.ClearContents
Dim web As Object
Set web = CreateObject("Microsoft.XMLHTTP")
start:
web.Open "GET", "https://docs.misoenergy.org/marketreports/20190315_sr_nd_is.xls", False
web.send
If web.Status = "200" Then
With ImportSht.QueryTables.Add(Connection:="URL;https://docs.misoenergy.org/marketreports/20190315_sr_nd_is.xls" _
, Destination:=ImportSht.Range("A1"))
.Name = "XLS_IMPORT"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End If
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub
I'm getting "Invalid Query" on .Refresh BackgroundQuery:=False when stepping through the code. Is there a way to import .xls files from the web using querytables? I've seen it done for .csv and I'm trying to adapt that code to xls.
Thank you for helping!
Sub XLSImport()
Dim ImportSht As Worksheet
Set ImportSht = Sheet6
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
ImportSht.Cells.ClearContents
Dim web As Object
Set web = CreateObject("Microsoft.XMLHTTP")
start:
web.Open "GET", "https://docs.misoenergy.org/marketreports/20190315_sr_nd_is.xls", False
web.send
If web.Status = "200" Then
With ImportSht.QueryTables.Add(Connection:="URL;https://docs.misoenergy.org/marketreports/20190315_sr_nd_is.xls" _
, Destination:=ImportSht.Range("A1"))
.Name = "XLS_IMPORT"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End If
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalculationAutomatic
End With
End Sub