Python win32com使用Bloomberg插件打开Excel [英] Python win32com opening Excel with Bloomberg plugin

查看:343
本文介绍了Python win32com使用Bloomberg插件打开Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动构建一个使用Bloomberg插件降低实时价格的Excel 2007电子表格.问题是,当我通过win32com打开Excel时,不会加载Bloomberg插件(因此所有公式都以"#NAME?"错误结尾).

I'm trying to automate construction of an Excel 2007 spreadsheet that uses the Bloomberg plugin to pull down live prices. The problem is that when I open Excel through win32com the Bloomberg plugin does not load (so all of the formulas end up with "#NAME?" errors).

手动卸载并重新安装插件是可行的,但是从录制的宏复制VBA代码会导致运行时错误'13':类型不匹配"错误.我可以单击结束"按钮,一切运行正常,但是我想让它完全自动化.

Manually uninstalling and reinstalling the plugin works, but copying the VBA code from the recorded macro leads to a "Run-time error '13': Type mismatch" error. I can click the End button and everything runs fine, but I want to have this fully automated.

我的代码是:

import win32com.client
xl = win32com.client.gencache.EnsureDispatch("Excel.Application")
xl.Visible = True
MainWorkBook = xl.Workbooks.Add(1)
xl.AddIns("Bloomberg Excel Tools").Installed = False
xl.AddIns("Bloomberg Excel Tools").Installed = True

设置DisplayAlerts = False不会捕获运行时错误.

Setting DisplayAlerts = False doesn't catch the runtime error.

推荐答案

您必须使用以下内容打开Bloomberg.xla文件:

you have to open the bloomberg.xla file with something like:

from win32com.client import DispatchEx
xl = DispatchEx('Excel.Application')
xl.Workbooks.Open('C:/blp/API/Office Tools/BloombergUI.xla')

有关更多信息,请参见此处: http://msdn.microsoft.com/en -us/library/microsoft.office.interop.excel.addin.aspx

see here for more info: http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.addin.aspx

这篇关于Python win32com使用Bloomberg插件打开Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆