在closures表单之前,VBA是否有可能等到Bloomberg字段被填充

我正在写一个VBA代码来执行以下操作:

打开一个Excel文件 – >从Bloomberg填充一系列单元格 – >closures并保存Excel文件。

他们的方式我已经写了代码,excel文件closures之前的细胞填充彭博价格。 任何想法如何修改它,所以它可以等待计算完成之前closures文件?

Sub GetSpreads() Workbooks.Open Filename:= _ "G:\Quant\Projects\Corp PD+LGD\PD Database\PD Database.xlsm", UpdateLinks:=0 Dim ws As Worksheet Dim rngTkr As Range Dim strTkr As String Dim c As Range Dim strFld As String Dim ws2 As Worksheet Dim dtBeg As Date Dim dtEnd As Date Dim strDtBeg As String Dim strdtEnd As String Windows("PD Database.xlsm").Activate Set ws = ActiveWorkbook.Sheets("Sheet3") Set ws2 = ActiveWorkbook.Sheets("Sheet3") ws.Activate Range("B2").Select With ws Set rngTkr = .Range(Selection, Selection.End(xlDown)) ' ticker range i = 1 For Each c In rngTkr strTkr = """" & c.Value & " Corp""" strFld = """" & "BLOOMBERG_MID_G_SPREAD" & """" strSort = """" & "Sort=D" & """" dtBeg = Cells(1, 9) ' adjust start date as you want dtEnd = Cells(2, 9) ' adjust end date as you want strDtBeg = """" & dtBeg & """" strdtEnd = """" & dtEnd & """" ws2.Range("N1").Offset(1, i).Value = "=BDH(" & strTkr & "," & strFld & "," & strDtBeg & "," & strdtEnd & "," & strSort & ")" ws2.Range("N1").Offset(0, i).Value = c.Value i = i + 2 Next End With Workbooks("PD Database.xlsm").Close savechanges:=True End Sub 

如果我没有记错的话,没有办法做到这一点 – 因为BBG正在使用某种DDE机制,所以Workbook.Calculate并不等待彭博社的更新。

一种方法是通过检查范围内的值来检查一秒钟左右的值是否刷新。

有关详细信息,请参阅http://www.vonixx.com/tips/tips34.htm