Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Avoiding 400 Error code

I have a macro which gets external data via a web query.

If for some reason a connection can't be made a 400 error appears. Is it
possible to add some code to mine below which says if connection fails
display message "Connection failed" press Get New Data to try again"

If so, what do I need and where exactly would I insert it into my code below?

Thanks a lot

Keith

-------

Sheets("Data").Select
If Range("a1").Value 0 Then
Range("A1:AJ65536").Select
Selection.ClearContents
Selection.QueryTable.Delete
End If
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.xyz.co.uk/extranet/mydata.asp",
Destination:=Range("A1"))
.Name = "mydata"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False

End With
Call next macro
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default Avoiding 400 Error code

right before add query add the line

on error goto GetNewData

then right above end sub add

exit sub
GetNewData:
'now add your message box to get new data



"nospaminlich" wrote:

I have a macro which gets external data via a web query.

If for some reason a connection can't be made a 400 error appears. Is it
possible to add some code to mine below which says if connection fails
display message "Connection failed" press Get New Data to try again"

If so, what do I need and where exactly would I insert it into my code below?

Thanks a lot

Keith

-------

Sheets("Data").Select
If Range("a1").Value 0 Then
Range("A1:AJ65536").Select
Selection.ClearContents
Selection.QueryTable.Delete
End If
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.xyz.co.uk/extranet/mydata.asp",
Destination:=Range("A1"))
.Name = "mydata"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False

End With
Call next macro
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Avoiding 400 Error code

Thanks Ben. Works a treat, brilliant!

"ben" wrote:

right before add query add the line

on error goto GetNewData

then right above end sub add

exit sub
GetNewData:
'now add your message box to get new data



"nospaminlich" wrote:

I have a macro which gets external data via a web query.

If for some reason a connection can't be made a 400 error appears. Is it
possible to add some code to mine below which says if connection fails
display message "Connection failed" press Get New Data to try again"

If so, what do I need and where exactly would I insert it into my code below?

Thanks a lot

Keith

-------

Sheets("Data").Select
If Range("a1").Value 0 Then
Range("A1:AJ65536").Select
Selection.ClearContents
Selection.QueryTable.Delete
End If
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.xyz.co.uk/extranet/mydata.asp",
Destination:=Range("A1"))
.Name = "mydata"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False

End With
Call next macro
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoiding error on Input Box - if no value is entered dhstein Excel Discussion (Misc queries) 5 April 25th 09 12:43 PM
Avoiding Value error message due to space in cell w/ formula A.R. Hunt Excel Discussion (Misc queries) 3 January 26th 07 09:52 PM
Avoiding the dreaded #div/0 error Marie1uk Excel Worksheet Functions 10 July 21st 05 10:49 PM
How can I still go to the error-code after a On Error Goto? Michel[_3_] Excel Programming 2 May 4th 04 04:21 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 01:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"