将在Excel VBA脚本中授权到BEAP(Bloomberg企业访问点)的解决方案是使用Bloomberg API并创建一个VBA对象来处理授权和数据请求。以下是一个代码示例:
' Bloomberg API reference required
'
' Declare variables
Dim Session As New blpapicomLib2.Session
Dim Service As blpapicomLib2.Service
Dim PiApi As blpapicomLib2.ProviderSession
Dim PiRequest As blpapicomLib2.Request
Dim FieldList As blpapicomLib2.Element
Dim SecurityList As blpapicomLib2.Element
Dim RequestSecurity As String
Dim RequestField As String
' Start session
If Not Session.Start Then
MsgBox "Could not start session.", vbExclamation
Exit Sub
Else
' Open service
Set Service = Session.GetService("//blp/mktdata")
' Login to Pi
Set PiApi = Service.OpenService("//blp/piapi")
If Not PiApi.Authorize Then
MsgBox "Could not authorize.", vbExclamation
Exit Sub
End If
' Create request
Set PiRequest = PiApi.CreateRequest("//blp/piapi/request")
' Set security and fields
RequestSecurity = "AAPL US Equity"
RequestField = "PX_LAST"
PiRequest.Set("security", RequestSecurity)
PiRequest.Set("fields", RequestField)
' Send request
PiApi.SendRequest PiRequest
' Get response
Do While PiApi.ProcessResponses(10000) > 0
Set SecurityList = PiRequest.GetElement("security")
Set FieldList = PiRequest.GetElement("fieldData")
' Output data
Debug.Print RequestSecurity & " " & RequestField & ": " & FieldList.GetElement(RequestField).Value
Loop
' Close Pi
PiApi.CloseService
End If
' Stop session
Session.Stop
注:这只是一个简单的示例,要使用Bloomberg API需要正确安装和配置才能使用。