PC Review


Reply
Thread Tools Rate Thread

Code Fails at this Line: .Refresh BackgroundQuery:=False

 
 
=?Utf-8?B?cnlndXk3Mjcy?=
Guest
Posts: n/a
 
      19th Oct 2007
Application.ScreenUpdating = False

Dim sngStart As Double
sngStart = Now


Dim str1 As String
Dim str2 As String
Dim c As Range
Dim Stocks As Range
Dim bFound As Boolean
Dim ws As Worksheet


Set Stocks = Application.InputBox( _
"Type 'Symbols' in the input box below", Type:=8)

For Each c In Sheets("Firms, Import").Range("Symbols")

bFound = False
For Each ws In Worksheets
If ws.Name = c.Value Then
bFound = True
Exit For
End If
Next ws

If bFound = False Then
Worksheets.Add.Name = c.Value
End If

'----------------------------------------------------------
Sheets(c.Value).Select
Cells.Select
Range("A1:IV65536").ClearContents

str1 = "URL;http://finance.yahoo.com/q/ks?s=" & _
c.Value

With ActiveSheet.QueryTables.Add(Connection:=str1 _
, Destination:=Range("A1"))

.Name = str1

.Name = "ks?s=c.Value"


.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = True
On Error GoTo Errorhandler:
.Refresh BackgroundQuery:=False
End With

Range("B").Select
Selection.Delete Shift:=xlToLeft
‘etc………….


Code sometimes fails on this line:
..Refresh BackgroundQuery:=False
(just a few lines above)

I’m baffled; I’m not sure why this happens. Sometimes the code runs fine,
and completes all import request (stock symbols listed in a column) and
sometimes it fails for no apparent reason. I added a few simple error
handlers (On Error Resume Next) and then the code ceases to do anything at
all. Does anyone know what may cause this behavior?

TIA,
Ryan---



--
RyGuy
 
Reply With Quote
 
 
 
 
=?Utf-8?B?cnlndXk3Mjcy?=
Guest
Posts: n/a
 
      23rd Oct 2007
After doing several more tests and some research on the web, I came to the
conclusion that it just fails when it is trying to find stocks that are not
followed very faithfully, or not well researched, or the like. It appears to
work fine for all the 'blue chips' and the popular securities; it definitely
becomes unreliable when querying for lesser known issues. I guess it's a
suggestion, of sorts, to stay away from those esoteric securities.



--
RyGuy


"ryguy7272" wrote:

> Application.ScreenUpdating = False
>
> Dim sngStart As Double
> sngStart = Now
>
>
> Dim str1 As String
> Dim str2 As String
> Dim c As Range
> Dim Stocks As Range
> Dim bFound As Boolean
> Dim ws As Worksheet
>
>
> Set Stocks = Application.InputBox( _
> "Type 'Symbols' in the input box below", Type:=8)
>
> For Each c In Sheets("Firms, Import").Range("Symbols")
>
> bFound = False
> For Each ws In Worksheets
> If ws.Name = c.Value Then
> bFound = True
> Exit For
> End If
> Next ws
>
> If bFound = False Then
> Worksheets.Add.Name = c.Value
> End If
>
> '----------------------------------------------------------
> Sheets(c.Value).Select
> Cells.Select
> Range("A1:IV65536").ClearContents
>
> str1 = "URL;http://finance.yahoo.com/q/ks?s=" & _
> c.Value
>
> With ActiveSheet.QueryTables.Add(Connection:=str1 _
> , Destination:=Range("A1"))
>
> .Name = str1
>
> .Name = "ks?s=c.Value"
>
>
> .WebSelectionType = xlEntirePage
> .WebFormatting = xlWebFormattingNone
> .WebPreFormattedTextToColumns = True
> .WebConsecutiveDelimitersAsOne = True
> .WebSingleBlockTextImport = False
> .WebDisableDateRecognition = False
> .WebDisableRedirections = True
> On Error GoTo Errorhandler:
> .Refresh BackgroundQuery:=False
> End With
>
> Range("B").Select
> Selection.Delete Shift:=xlToLeft
> ‘etc………….
>
>
> Code sometimes fails on this line:
> .Refresh BackgroundQuery:=False
> (just a few lines above)
>
> I’m baffled; I’m not sure why this happens. Sometimes the code runs fine,
> and completes all import request (stock symbols listed in a column) and
> sometimes it fails for no apparent reason. I added a few simple error
> handlers (On Error Resume Next) and then the code ceases to do anything at
> all. Does anyone know what may cause this behavior?
>
> TIA,
> Ryan---
>
>
>
> --
> RyGuy

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
.Refresh BackgroundQuery:=False Basta1980 Microsoft Excel Programming 2 24th Sep 2008 12:00 PM
.Refresh BackgroundQuery:=False qcan Microsoft Excel Programming 0 10th Mar 2008 03:12 PM
.Refresh BackgroundQuery:=False ikirin Microsoft Excel Programming 0 26th Jun 2006 04:01 PM
.Refresh BackgroundQuery:=False ikirin Microsoft Excel Programming 0 26th Jun 2006 03:46 PM
Excel does not close from VB!! (when i refresh Refresh query with BackgroundQuery:=False) Anant Microsoft Excel Programming 1 6th Aug 2003 04:22 AM


Features
 

Advertising
 

Newsgroups
 


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