choubix
02-11-2008, 04:33 AM
hello,
I am really rusty in vba and I'd like to understand the following portion of code.
what it does: retrieve historical data from yahoo finance for a series of tickers.
Sub PHExample2()
Dim sTicker As String
[PHResults2].ClearContents
Application.Calculation = xlCalculationManual
Set objPH = PriceHistory
For i = 1 To [PHTickerGroup].Columns.Count
sTicker = [PHTickerGroup].Cells(1, i)
nNumItems = objPH.GetPriceHistory("yahoo", sTicker, [PHStartDate].Value, _
[PHEndDate].Value, [PHFrequency].Value, [PHAllDates].Value)
[PHError].Value = objPH.ErrorDescription
If nNumItems = 0 Then GoTo fin
For j = 1 To nNumItems
objPH.Item = j
If i = 1 Then [PHResults2].Cells(j, 1) = objPH.PriceDate
If objPH.priceclose <> 0 Then 'omit any non-trading days
[PHResults2].Cells(j, i + 1) = objPH.PriceAdjClose
End If
Next j
Next i
fin:
Application.Calculation = xlCalculationAutomatic
End Sub
What I don't understand:
- what are xlcalculationmanual and xlcalcualtionautomatic are for in this code?
- I don't fully understand how the 2nd loop works. it is supposed to remove non trading days but I don't understnad how this works.
hope someone can enlight me :)
thanks!
Alex
I am really rusty in vba and I'd like to understand the following portion of code.
what it does: retrieve historical data from yahoo finance for a series of tickers.
Sub PHExample2()
Dim sTicker As String
[PHResults2].ClearContents
Application.Calculation = xlCalculationManual
Set objPH = PriceHistory
For i = 1 To [PHTickerGroup].Columns.Count
sTicker = [PHTickerGroup].Cells(1, i)
nNumItems = objPH.GetPriceHistory("yahoo", sTicker, [PHStartDate].Value, _
[PHEndDate].Value, [PHFrequency].Value, [PHAllDates].Value)
[PHError].Value = objPH.ErrorDescription
If nNumItems = 0 Then GoTo fin
For j = 1 To nNumItems
objPH.Item = j
If i = 1 Then [PHResults2].Cells(j, 1) = objPH.PriceDate
If objPH.priceclose <> 0 Then 'omit any non-trading days
[PHResults2].Cells(j, i + 1) = objPH.PriceAdjClose
End If
Next j
Next i
fin:
Application.Calculation = xlCalculationAutomatic
End Sub
What I don't understand:
- what are xlcalculationmanual and xlcalcualtionautomatic are for in this code?
- I don't fully understand how the 2nd loop works. it is supposed to remove non trading days but I don't understnad how this works.
hope someone can enlight me :)
thanks!
Alex