[pyxl] Running Macro Code from python.

3,787 views
Skip to first unread message

rod

unread,
Apr 22, 2010, 8:32:01 AM4/22/10
to python-excel
Hi,

I am generating a report in excel which is fully automated, which will
run every day. I now want to add macro to the report. The code used to
generate the report is PYTHON.

Now how to automate the report. Can i use python to run the macro? Or
should i use the excel macro code ( VB ) itself in python to run it?

Can someone please help me out.

--
Vinoth

--
You received this message because you are subscribed to the Google Groups "python-excel" group.
To post to this group, send an email to python...@googlegroups.com.
To unsubscribe from this group, send email to python-excel...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/python-excel?hl=en-GB.

geoff_ness

unread,
Apr 23, 2010, 5:05:12 AM4/23/10
to python-excel
Hi Vinoth

If you want to run a VBA process from python, you can, but you'd have
to use COM to do so. There's an example at
http://excelicious.wordpress.com/2009/05/09/why-id-like-python-at-work-part-2/
if this is what you need.

However, it's not clear from what you wrote why you would need to do
this. If you are already generating the reports using python, I don't
see why you couldn't use python to automate the process...what is it
you need VBA for?

rod

unread,
Apr 27, 2010, 3:32:19 AM4/27/10
to python-excel
Hi,

I just want to make macro automated using python. I googled and found
win32com is one package used to do that, but it is for windows. I am
using Linux and pyexcelerator package to write in excel, is there any
possibility that we can automate a MACRO using python, is tre any
specific package kind of stuff used for it.

If macro automation is not possible, is there any way to make drop
down box in excel... If i can do this i can make the viewers of my
excel to feel as if i have added a macro.

Thanks in advance.


On Apr 23, 2:05 pm, geoff_ness <geoffne...@gmail.com> wrote:
> Hi Vinoth
>
> If you want to run a VBA process from python, you can, but you'd have
> to use COM to do so. There's an example athttp://excelicious.wordpress.com/2009/05/09/why-id-like-python-at-wor...

geoff_ness

unread,
Apr 27, 2010, 6:18:53 AM4/27/10
to python-excel


On Apr 27, 7:32 pm, rod <vinoth....@gmail.com> wrote:
> Hi,
>
> I just want to make macro automated using python. I googled and found
> win32com is one package used to do that, but it is for windows. I am
> using Linux and pyexcelerator package to write in excel, is there any
> possibility that we can automate a MACRO using python, is tre any
> specific package kind of stuff used for it.
>
Depends entirely on what you mean by "automate a MACRO using python".
Here are some possible interpretations:
(1) You want to recreate the effect of a sequence of operations in the
Excel application on an Excel workbook or set of Excel workbooks. The
xlrd, xlwt and xlutils packages contain plenty of ways to do this,
depending on what those operations are.

(2) You want to run some pre-existing VBA code in an Excel workbook
from python. You'll need to use COM via win32com.

(3) You want to call to the python interpreter from within Excel,
maybe to perform the sequence of operations from (1). Possible -
there's an example at
http://blog.gobansaor.com/2010/02/07/xlite-beta-updated-adds-python-as-an-excel-scripting-language/

Which of these sounds closest to what you want to do?

> If macro automation is not possible, is there any way to make drop
> down box in excel... If i can do this i can make the viewers of my
> excel to feel as if i have added a macro.
>
There are many ways to place a drop-down box on an Excel worksheet,
via Data Validation, an MS Forms Combobox, an Activex Combobox... the
most appropriate depends on what you wish the drop-down box to do.

Chris Withers

unread,
Apr 27, 2010, 9:03:05 AM4/27/10
to python...@googlegroups.com
rod wrote:
> I just want to make macro automated using python. I googled and found
> win32com is one package used to do that, but it is for windows. I am
> using Linux and pyexcelerator package to write in excel,

WHY are you using PyExcelerator?
What part of "DO NOT USE PYEXCELERATOR" are you missing?

xlwt has been actively advertised for SOME YEARS now.

sheesh.

Chris

rod

unread,
Apr 28, 2010, 7:28:54 AM4/28/10
to python-excel
Hi Chris,

I actually started using pyExcelerator a long time back and still
continuing. Now i have implemented it in lot of codes.
When i created my first report i did not think i am going to use it in
a wide range

But now its time for me to use some efficient library which can be
used to write macro codes etc... Which one do you recommend?

--- Vinoth R

Chris Withers

unread,
Apr 28, 2010, 9:15:38 AM4/28/10
to python...@googlegroups.com
rod wrote:
> I actually started using pyExcelerator a long time back and still
> continuing. Now i have implemented it in lot of codes.
> When i created my first report i did not think i am going to use it in
> a wide range

It's a matter of changing imports, if you'd bothered to look into it.

> But now its time for me to use some efficient library which can be
> used to write macro codes etc... Which one do you recommend?

You're on your own there, no libraries I know of support that.

cheers,

Chris

--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
Reply all
Reply to author
Forward
0 new messages