I'm currently using the Bloomberg add-in in Excel and utilizing the BDP function.
I want to automate a process where, upon changing the selection in a dropdown list, the cells in the sheet that depend on this selection will refresh accordingly, and then output the sheet to a PDF file.
This process should repeat for each item in the dropdown list.
While there's no issue with Excel's general functions, I've encountered a problem where the cells don't refresh when I change the selection in the dropdown list if they are using the BDP function.
Could someone advise on how to ensure the cells refresh when using the BDP function in this context?
Option Explicit
Sub printPDF()
Dim ws As Worksheet
Dim validationCell As Range
Dim validationFormula As String
Dim saveFolder As String
Dim pdfName As String
Dim item As Variant
Dim dropdownValues As String
Set ws = ActiveSheet
Selt validationCell = ws.Range("AF1") 'location of pulldown list
validationFormula = validationCell.Validation.Formula1
'path
savFolder = ws.Range(A1)
If Right (saveFolder, 1) <> "\" Then
saveFolder = saveFolder & "\"
End If
If Left(validationFormula, 1) = "=" Then
Dim listRange As Range
Set listRange = ws.Evaluate(Mid(validationFormula,2))
ReDim dropdownValues(listRange.Cells.CountLarge - 1)
Dim i As Long
i = 0
Dim cell As Range
For Each cell In listRange
dropdownValues(i) = cell.Value
i = i+1
Next cell
End If
If UBound(dropdownValues) >= 0 Then
validationCell.Value = dropdownValues(0)
End If
Application.Calculation = xlCalculationAutomatic
For Each item In dropdownValues
'change pull down
validationCell.Value = item
Application.Calculate
'wait
Do While Application.CalculationState <> xlDone
DoEvents
Loop
'Name of PDF
pdfName = ws.Range("AF2").Value & "_" & Format(Now, "yyyymndd_hhamss")
'Save as PDF
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveFolder & pdfName & ".pdf", quality:=xlQualityStandard
Next item
MsgBox “Done”
Shell "explorer.exe """ & saveFolder & """", vbNormalFocus
End Sub