1

I am trying to run Excels Solver add-in via pywin32 in python with:

import win32com.client
from win32com.client import constants as c

app = Dispatch("Excel.Application")
app.Visible = True
app.Workbooks.Open(r'C:\path\to\testsolver.xlsm')
app.Run("runsolver")

..but get the following error:

"Cannot run the macro 'runsolver'. The macro may not be available in this workbook or all  macros may be disabled"
3
  • I can't recall whether the solver is installed in Excel by default. You may need to go into Options and tell it somehow that you want the solver. Commented Mar 18, 2013 at 1:46
  • I have the solver add-in activated actually and it is working fine if I start it manually Commented Mar 18, 2013 at 1:59
  • COM/ActiveX security? Commented Mar 19, 2013 at 2:41

1 Answer 1

2

I realise this is a year old, but in case this is still of value the problem here may be that Solver is not automatically loaded when an Excel OLE object is created. By design, add-ins must be loaded manually before they can be used in an Excel OLE object.

You can confirm that it isn't loaded by examing the OLE created instance and going to the "Data" tab and observing that Solver doesn't appear there, like it does when you open Excel from the Windows GUI.

I discovered this while trying to solve a similar problem in Delphi code as described here:

CreateOleObject opened workbook won't run macro containing Application.Run "Solver.xlam!..." causes error 400

I expect the Python syntax will be similar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.