问题
I am trying to open an excel which is connected to BBG and refresh values.
To open an instance of excel and load bloomberg addins, I used a solution from the attached link a while ago Python using win32com wont update excel sheet with needed Add-ins
The solution worked fine for me till yday when for some reason xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')
is giving me trouble. i.e. not loading and crashing my codes.
Anyone has any ideas whats happening?
Codes are below if anyone interested
import os, os.path
import win32com.client
xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')
xlapp.Workbooks.Open('C:\\blp\\API\\Office Tools\\BloombergUI.xla')
wb = xlapp.Workbooks.Open(filepath,None,False)
xlapp.Visible = True
wb_addin = ('C:/blp/API/Office Tools/bofaddin.dll')
wb.RefreshAll()
回答1:
Try importing time and putting time.sleep(2) after each command. I found the Bloomberg links sometimes need a second to update.
xlapp = win32com.client.DispatchEx("Excel.Application")
time.sleep(2)
xlapp.RegisterXLL('C:/blp/API/Office Tools/bofaddin.dll')
time.sleep(2)
xlapp.Workbooks.Open('C:\\blp\\API\\Office Tools\\BloombergUI.xla')
time.sleep(2)
wb = xlapp.Workbooks.Open(filepath,None,False)
xlapp.Visible = True
wb_addin = ('C:/blp/API/Office Tools/bofaddin.dll')
来源:https://stackoverflow.com/questions/62320267/trouble-loading-bloomberg-addins-on-excel-using-python