views:

209

answers:

1

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).

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.

My code is:

import win32com
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

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

A: 

Sorry the first line should be

import win32com.client
Bill
DON'T answer your own question. DO edit your question to correct mistakes like that. It helps when entering code to copy/paste the actual code that you ran; don't re-type what you thought that you ran.
John Machin