Hi Maria, try this.
if the web page is not found it will delete all query connections, exit sub and give message as to what URL was not found
Sub checkURL()
Dim URL, MyRange As Range
Set MyRange = Sheet1.Range("A1:A" & Sheet1.Range("A" & Rows.Count).End(xlUp).Row)
For Each URL In MyRange
If URL.Value <> "" Then
ActiveWorkbook.Worksheets.Add
on error goto errorhandler
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.website.com/" & URL & "secondpartofurl" _
, Destination:=Range("$A$1"))
.Name = "placeholder"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlSpecifiedTables
.WebFormatting = xlWebFormattingNone
.WebTables = "16"
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Call DeleteAllQueries
End If
Next
Exit Sub
errorhandler:
Err.Clear
Call DeleteAllQueries
MsgBox URL & " Web page not found",vbinformation, "Error"
End Sub
Sub DeleteAllQueries() 'breaks quieres
Dim qt As QueryTable
Dim WSh As Worksheet
For Each WSh In ThisWorkbook.Worksheets
For Each qt In WSh.QueryTables
qt.Delete
Next qt
Next WSh
End Sub
Bookmarks