Running Excel Macro from Ruby

imaband

New Member
Joined
Dec 16, 2008
Messages
3
Hi,

I have a problem which involves calling an excel macro from another application – in this case, ruby.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p><o:p></o:p>
$excel.Run "ActionCommands.xlsm!CreateDynamicDataSources"
<o:p></o:p><o:p></o:p>
Here is the simplified macro that it calls
<o:p></o:p>
Sub CreateDynamicDataSources()<o:p></o:p>
<o:p></o:p>
MsgBox "Hello"<o:p></o:p>
ActiveCell.Select<o:p></o:p>
ActiveCell.Formula = "Hello"<o:p></o:p>
<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
The good news is, the macro is indeed being called because the MsgBox is executing. It may even be able to read cells and send the data back to ruby or display it in a message box. The bad news is I can’t select a sheet or cell and actually write to it! When I call this macro from Excel it works as expected. How do I fool Excel (2007) into thinking it’s OK to allow these operations. There is no explicit message that says “Hey this is in read only mode” but I suspect that is what is going on. Does anyone know of a work-around, solution, or better way of doing this?
<o:p></o:p>
Jeff
 
It also works like this:

Code:
import win32com.client

xls = win32com.client.Dispatch("Excel.Application")
xls.visible = True
xls.Run(r"'c:\guillermo\dev\tmp\test.xlsm'!DoStuff", "Hello from Python!")
xls.ActiveCell.EntireColumn.AutoFit()
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,215,966
Messages
6,127,972
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top