tiehaze
asked on
Using excel with Bloomberg BLP functions
I have code set up to download information off of a Bloomberg terminal. Column A consists of CUSIPS and SEDOLS, which I use in BLP formulas. Because I have roughly 10,000 Cusips, the download of all of this data takes about an hour.
I am wondering if there is anything I can write in my code that tells it to wait until the data is completely downloaded, and then execute 'Code A' and then save and close it.
I am wondering if there is anything I can write in my code that tells it to wait until the data is completely downloaded, and then execute 'Code A' and then save and close it.
You MIGHT be able to intercept the Worksheet_Calculate event which is triggered at the end of every calculation - and since the Bloomberg worksheet functions are only evaluated as part of a worksheet calculation request, this might work.
Private Sub Worksheet_Calculate()
' Check to see if all Bloomberg results are in for the day
' If so then saev and close the workbook
End Sub
Kevin
Private Sub Worksheet_Calculate()
' Check to see if all Bloomberg results are in for the day
' If so then saev and close the workbook
End Sub
Kevin
ASKER
The above code is foreign to me. Lets use my example:
Run Macro: 'Formulas' which adds all of the BLP formulas
Run Macro: 'Finish' copies and pastes values of all of the cells, and then saves and closes the file
Would I just copy the code you gave me in between the two macros 'Formulas' and 'Finish'?
Run Macro: 'Formulas' which adds all of the BLP formulas
Run Macro: 'Finish' copies and pastes values of all of the cells, and then saves and closes the file
Would I just copy the code you gave me in between the two macros 'Formulas' and 'Finish'?
>Would I just copy the code you gave me in between the two macros 'Formulas' and 'Finish'?
No. That was just some sample code illustrating how to use the DDE API calls.
Try this:
Application.Calculation = xlCalculationManual
Formulas
Sheets("BloombergPullSheet ").Calcula te
Finish
Kevin
No. That was just some sample code illustrating how to use the DDE API calls.
Try this:
Application.Calculation = xlCalculationManual
Formulas
Sheets("BloombergPullSheet
Finish
Kevin
ASKER
Kevin, I tried the code above and it did not work. All of the values were NAs because it didn't wait to finish calculating before it copied and pasted the values. You mentioned trying:
Private Sub Worksheet_Calculate()
' Check to see if all Bloomberg results are in for the day
' If so then saev and close the workbook
End Sub
How do I check to see if all Bloomberf results are in?
Private Sub Worksheet_Calculate()
' Check to see if all Bloomberg results are in for the day
' If so then saev and close the workbook
End Sub
How do I check to see if all Bloomberf results are in?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
' Establish DDE connection
#If BloombergInstalled Then
ChannelNumber = DDEInitiate("Blp", "H")
#End If
' TickerIndex is used to count tickers
TickerIndex = 1
' Determine number of tickers for the status
Count = WorksheetFunction.CountA(w
FieldCodesString.Delimiter
ReDim CompleteResults(1 To 100, 1 To wksResults.FieldCodes.Cell
' For each ticker...
For Each TickerCell In wksTickers.Ticker
PeriodCount = 0
For FieldIndex = 1 To wksResults.FieldCodes.Cell
For Period = 1 To UBound(CompleteResults, 1)
CompleteResults(Period, FieldIndex) = "#N/A Not Retr"
Next
Next
ErrorOccurred = False
' Stop if a blank ticker (end of list)
If Len(TickerCell.Value) = 0 Then Exit For
' Display the status
Environment.Status = "Procesing ticker " & TickerIndex & " out of " & Count
' Set up the DDE call command line parts
CommandLine1 = TickerCell.Value & " Equity, ["
CommandLine2 = "], PT=4Y END=" & Format(EndDate.Value, "YYYYMMDD") & " PD=" & Periodicity
' Build results
FieldCodeIndex = 1
Do
'For FieldCodeIndex = 1 To wksResults.FieldCodes.Cell
' Execute the DDE command
FirstFieldIndex = FieldCodeIndex
FieldCodesString.Value = ""
#If BloombergInstalled Then
Do
If Len(FieldCodesString.Value
Exit Do
Else
FieldCodesString.Append wksResults.FieldCodes(Fiel
End If
FieldCodeIndex = FieldCodeIndex + 1
Loop Until FieldCodeIndex > wksResults.FieldCodes.Cell
On Error Resume Next
Results = DDERequest(ChannelNumber, CommandLine1 & FieldCodesString.Value & CommandLine2)
If Not Err.Number = 0 Then ' Or Left(Results, 5) = "Error" Then
ErrorOccurred = True
Exit For
End If
#Else
ReDim Results(2, 2)
Results(1, 1) = 123
Results(1, 2) = FieldCodeIndex + 100
Results(2, 1) = 456
Results(2, 2) = FieldCodeIndex + 200
#End If
LastFieldIndex = FieldCodeIndex - 1
PeriodCount = Max(PeriodCount, UBound(Results, 1))
' Add results to complete results
For Period = 1 To UBound(Results, 1)
For FieldIndex = FirstFieldIndex To LastFieldIndex
If FieldIndex = 1 Then
CompleteResults(Period, 1) = Results(Period, 1)
End If
CompleteResults(Period, FieldIndex + 1) = Results(Period, FieldIndex - FirstFieldIndex + 2)
Next
Next
'Next
Loop Until FieldCodeIndex > wksResults.FieldCodes.Cell
If ErrorOccurred Then
wksTickers.Error(TickerInd
Else
' Define destination ranges
Set ResultTickerPasteArea = wksResults.TickerPasteArea
Set ResultValuesPasteArea = wksResults.ValuesPasteArea
' Paste the values
ResultTickerPasteArea.Valu
ResultValuesPasteArea.Valu
End If
' Bump the TickerIndex used to display the status
TickerIndex = TickerIndex + 1
Next
' End DDE conversation
#If BloombergInstalled Then
DDETerminate ChannelNumber
#End If
Kevin