How do I handle URL connections - such as logging into a web application?
Example 1
When I use .Refresh BackgroundQuery:= False and there is a problem connecting, Excel hangs ... cannot Ctrl-Break ... only option is to kill Excel (and lose changes).
global QT As QueryTable
Set QT = ActiveSheet.QueryTables.Add(Connection:="URL;" & vLoginURL, Destination:=Range("A1"))
With QT
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebSingleBlockTextImport = False
.Refresh BackgroundQuery:= False
End With
Example 2
When I use .Refresh BackgroundQuery:= True, I need to give it time to refresh. Application.Wait, DoEvent, do while, etc don't let the querytable return data to the destination. So I use the following method:
Set QT = ActiveSheet.QueryTables.Add(Connection:="URL;" & vLoginURL, Destination:=Range("A1"))
With QT
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebSingleBlockTextImport = False
.Refresh BackgroundQuery:=True
End With
dTime = Now + TimeValue("00:00:05")
Application.OnTime dTime, "chkLogin"
Sub chkLogin()
If not(QT is Nothing) then
With QT
if .Refreshing Then .CancelRefresh
End with
End sub
Now, if it's still refreshing, it's ok. But if not, it gets stuck on .Refreshing with run time error 424.
Ideally I want to use .Refresh BackgroundQuery:= False
as I am calling a number of urls. I just need to provide an "out" when the url fails and hangs on .Refresh BackgroundQuery:= False
Any ideas?
Example 1
When I use .Refresh BackgroundQuery:= False and there is a problem connecting, Excel hangs ... cannot Ctrl-Break ... only option is to kill Excel (and lose changes).
global QT As QueryTable
Set QT = ActiveSheet.QueryTables.Add(Connection:="URL;" & vLoginURL, Destination:=Range("A1"))
With QT
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebSingleBlockTextImport = False
.Refresh BackgroundQuery:= False
End With
Example 2
When I use .Refresh BackgroundQuery:= True, I need to give it time to refresh. Application.Wait, DoEvent, do while, etc don't let the querytable return data to the destination. So I use the following method:
Set QT = ActiveSheet.QueryTables.Add(Connection:="URL;" & vLoginURL, Destination:=Range("A1"))
With QT
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebSingleBlockTextImport = False
.Refresh BackgroundQuery:=True
End With
dTime = Now + TimeValue("00:00:05")
Application.OnTime dTime, "chkLogin"
Sub chkLogin()
If not(QT is Nothing) then
With QT
if .Refreshing Then .CancelRefresh
End with
End sub
Now, if it's still refreshing, it's ok. But if not, it gets stuck on .Refreshing with run time error 424.
Ideally I want to use .Refresh BackgroundQuery:= False
as I am calling a number of urls. I just need to provide an "out" when the url fails and hangs on .Refresh BackgroundQuery:= False
Any ideas?