PDA

View Full Version : Solved: How to force Excel to reconnect to website?



Bonaparte
12-07-2007, 11:41 PM
Hi, I'm trying to extract data from a website every 5 seconds interval.
Things are going well. However, sometimes when the server is busy, excel return with an error:

Unable to open:

<Website address>

Cannot locate the internet server or proxy server.

Is there a way to force the application to wait for abt 60 seconds, then
reconnect the the website automatically?

Mycodes:

Sub The_Sub()

Dim x As Long

With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.soccernet.com", Destination _
:=Range("A1"))
.Name = "product-desc.php?auction=07B003D"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 1
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False



End With
Worksheets("Sheet1").Cells(12, 3).Value = Time

Call GetLastUsedCell(2)

Sheet1.Activate
StartTimer

End Sub

Zack Barresse
12-08-2007, 11:32 AM
Hi there,

If I understand you correctly, you may want to look at the Wait command..

Sub The_Sub()
Dim x As Long
On Error Resume Next
StartQuery:
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;https://www.soccernet.com", Destination _
:=Range("A1"))
.Name = "product-desc.php?auction=07B003D"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 1
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
If Err.Number = 1004 Then
Application.Wait Now + TimeValue("0:00:60")
Err.Clear
GoTo StartQuery
End If
Worksheets("Sheet1").Cells(12, 3).Value = Time
Call GetLastUsedCell(2)
Sheet1.Activate
StartTimer
End Sub

HTH

Bonaparte
12-10-2007, 12:14 PM
Thanks fire!
Works a treat:)