LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Data Connection Proliferation

I cobbled together a set of macros (below) to periodically query Yahoo
finance and download quotes. This spreadsheet would ideally run 24/7. I
noticed after a few weeks that it grew larger and slower. I discovered, under
Data Connections, about 7000 identical connections that had been created (and
saved). Just deleting them will be a massive chore, but avoiding them
entirely would be desirable.

Obviously I'm doing something wrong here. Any help appreciated.

Code begins:
Public RunWhen As Double
Public PauseStuff As Boolean
Public Const cRunIntervalSeconds = 120 ' two minutes
Public Const cRunWhat = "GetData" ' the name of the procedure to run


Sub StartTimer()
RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=True
'PauseStuff = True 'if true, getdata
End Sub



Sub GetData()

Dim QuerySheet As Worksheet
Dim DataSheet As Worksheet
Dim qurl As String
Dim i As Integer
On Error Resume Next
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
If Not PauseStuff Then GoTo OnPause
Set DataSheet = Worksheets("Sheet2")
DataSheet.Activate
Range("A30").CurrentRegion.ClearContents
Range("b2").Select
i = 1
yahoourl = "http://quote.yahoo.com/d/quotes.csv?s=^GSPC + " +
ActiveCell.Value

ActiveCell.Offset(1, 0).Select
While ActiveCell < ""
yahoourl = yahoourl + "+" + ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Wend
yahoourl = yahoourl + "&f=nl1c"

QueryQuote:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & yahoourl,
Destination:=Range("A30"))
.BackgroundQuery = True
.TablesOnlyFromHTML = False
.Refresh BackgroundQuery:=False
.SaveData = True
End With

Range("a30").CurrentRegion.TextToColumns
Destination:=Range("a30"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=True, _
Semicolon:=False, Comma:=True, Space:=False, other:=False

Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Columns("A:A").ColumnWidth = 28#
'Cells(2, 3).Select
OnPause:
StartTimer

End Sub
Sub StopTimer()
On Error Resume Next
Application.OnTime EarliestTime:=RunWhen, Procedu=cRunWhat,
Schedule:=False
End Sub
Sub Pausequery()
PauseStuff = Not PauseStuff
Worksheets("Yahoo").Activate
If Range("A1") = "" Then Range("A1") = "WEB QUERY PAUSED" Else Range("a1") =
""

End Sub
 
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
When I save a workbook(2007) w/ a data connection to htm no data? Robert Excel Discussion (Misc queries) 0 July 13th 09 01:39 AM
Data Connection dhstein Excel Discussion (Misc queries) 0 October 22nd 08 10:00 PM
Importing:Data Connection Wizard Doesn't see Source Data - No Impo Exotic Hadron Excel Discussion (Misc queries) 0 October 1st 08 07:35 PM
always recheck data connection library for latest connection strin FurmanGG Excel Discussion (Misc queries) 0 September 14th 07 04:48 PM
always recheck data connection library in MOSS for latest data sou FurmanGG Excel Discussion (Misc queries) 0 September 14th 07 04:48 PM


All times are GMT +1. The time now is 11:38 PM.

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

About Us

"It's about Microsoft Excel"