Re: Different Macro behavior when called from Immediate Window vs.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Regardless of how i import the data, I want to erase the previous data
automatically. Try this with a new workbook:
Type text into cell A1.
Add this macro into module -
Function EraseA1() As Boolean

If (ActiveSheet.Cells(1, 1) <> Empty) Then
ActiveSheet.Cells(1, 1).Delete
End If
If (ActiveSheet.Cells(1, 1) <> Empty) Then
EraseA1 = False
Else
EraseA1 = True
End If
End Function

Now in another cell on the same worksheet use the formula =EraseA1(). The
result is FALSE.
Now in the immediate window type x = EraseA1(), and Cell A1 on the worksheet
gets erased.

What am I missing?

"Don Guillett" wrote:

This is the sort of thing I do for clients on a daily basis.

I think you would be much better off using data>import external data>new>put
in your url>import.
Then record a macro while doing. Then modify to put into a loop and copy
desired data from the fetch sheet to another sheet with just the data you
want. Send a workbook to my address below with your symbols, etc and I will
take a look.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
dguillett1@xxxxxxxxxxxxx
"TimWms" <TimWms@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BAC765D6-13F8-4AEC-9A38-B03F0ECA4C09@xxxxxxxxxxxxxxxx
I'm not sure if you will be able to follow along....

Rem Load Option Chain Pricing from Yahoo using the web address
Rem http://finance.yahoo.com/q/os?s=YHOO&m=2008-01
Rem NOTE: Whenever a .refresh is executed, function may be called again
from
the beginning, function must be reentrant

Function LoadChains(Stock As String, NextExp As Date, Series As Integer)
As
Boolean

Dim ws As Worksheet
Dim conn As String, newconn As String
Dim i As Integer
Static LastCRef(4) As Date


If NextExp <> 0 Then
Set ws = Worksheets("Chain " & Format(Series, "#0"))

If ws.QueryTables.Count <> 0 Then
conn = ws.QueryTables(1).Connection
End If

newconn = "URL;http://finance.yahoo.com/q/os?s="; _
& Stock _
& "&m=" & Format(NextExp, "yyyy") & "-" & Format(NextExp, "m")

If conn <> newconn Then
Do While ws.QueryTables.Count <> 0
ws.QueryTables(1).Delete
Loop
LastCRef(Series) = 0
If ws.Cells(1, 1) <> Empty Then
ws.Range("A1:O50").ClearContents
End If
With ws.QueryTables.Add( _
Connection:=newconn, Destination:=ws.Cells(1, 1))
.BackgroundQuery = False
.EnableRefresh = True
.EnableEditing = True
.FillAdjacentFormulas = True
Rem .Name = "Chain" & Format(Series, "#0") & "_" & Stock
.RefreshOnFileOpen = True
.RefreshStyle = xlOverwriteCells
.SaveData = True
.WebSelectionType = xlSpecifiedTables
.WebTables = "8,12"
End With
End If
If (LastCRef(Series) - LastClose()) < 0 Then ' if close has
occurred since last refresh
ws.QueryTables(1).Refresh (False)
LastCRef(Series) = Now
End If
LoadChains = True

Else ' NextExp = 0 - do nothing
LoadChains = False
End If
End Function



.



Relevant Pages

  • Re: enable automatic refresh
    ... You are prompted to enable automatic refresh when you open a workbook ... Options available in the Query Refresh dialog box ... Using the QuerySecurity registry entry to configure Excel ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Excel/Access Delimma - Suggestions Welcome
    ... Your original post stated the "update links" message was coming up. ... A message to "refresh query" is not the same as updating links. ... Save the workbook. ...
    (microsoft.public.excel)
  • RE: how do I get a formula to automatically refresh thats a macro
    ... an empty cell on the sheet and type a number, any number, into it. ... ' of a cell, or, if OfText is true, of the Font in the cell. ... CountByColor = CountByColor - _ ... But I have to redrag it to get it to refresh after I highlight cells... ...
    (microsoft.public.excel.worksheet.functions)
  • Re: macro to disable auto refresh
    ... Now that I reopened the sample workbook I created yesterday, ... the workbook with the queries. ... It sounds like you could deselect the 'Refresh data on file open' ... For Each WkSht In .Worksheets ...
    (microsoft.public.excel.programming)
  • Re: refresh data vba question
    ... I believe he meant there is a button on the sheet that ... > To change it, select the workbook in the VBE, and change the Name property ... >> Sub Refresh() ...
    (microsoft.public.excel.programming)