I have a spreadsheet which works fine and was created in Excel 2010. We will be upgrading to Excel 2016 soon, but for some strange reason my script will not work on newer versions of Excel. I don't even know where to begin trouble shooting this, as it seems to me it should work fine across all versions. My code is below. I also attached my file.
Sub Test()
ActiveSheet.Unprotect Password:=""
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.wsj.com/market-data/bonds", Destination:=Range("$B$2"))
.Name = "myQuery"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebTables = "1"
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Dim L&
With CreateObject("WinHttp.WinHttpRequest.5.1")
.Open "GET", "https://www.wsj.com/market-data/bonds", False
.setRequestHeader "DNT", "1"
.send
If .Status = 200 Then
L = InStr(.responseText, "Rates shown are effective")
If L Then ActiveSheet.Range("A12") = Mid(.responseText, L, InStr(L, .responseText, "</") - L)
End If
End With
ActiveSheet.Protect Password:=""
End Sub
Bookmarks