Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Use macros in Excel via win32com

Reply
Thread Tools

Use macros in Excel via win32com

 
 
chris
Guest
Posts: n/a
 
      12-19-2004
I'm creating an excel document dynamically from scratch using Python
and the win32com module. All is well, but now I need to add a macro to
the spreadsheet and run it (to enable some sorting features in the
spreadsheet). I think I know how to run a macro once it's installed
(using the Run method of the excel application object...I think), but I
can't figure out how to "install" the VBA macro code into the
spreadsheet to begin with from my Python script.
Any tips appreciated.

Thanks,
Chris

 
Reply With Quote
 
 
 
 
beliavsky@aol.com
Guest
Posts: n/a
 
      12-19-2004

"chris" <(E-Mail Removed)> wrote:
>I'm creating an excel document dynamically from scratch using Python
>and the win32com module. All is well, but now I need to add a macro to
>the spreadsheet and run it (to enable some sorting features in the
>spreadsheet). I think I know how to run a macro once it's installed
>(using the Run method of the excel application object...I think), but I
>can't figure out how to "install" the VBA macro code into the
>spreadsheet to begin with from my Python script.
>Any tips appreciated.


Here is a manual solution for Excel 2003. At the bottom of the spreadsheet,
right-click on one of the tabs (default names sheet1 sheet2 sheet3). Click
"view code" on the menu, which should bring up a Microsoft Visual Basic editor.
Select Module from the Insert menu at the top, and paste the VBA code there.



----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
 
Reply With Quote
 
 
 
 
chris
Guest
Posts: n/a
 
      12-19-2004
Thanks, but the problem is that I need to create the entire Excel
document from scratch, dynamically, via the Python script. I want the
script to add the macro code.

-Chris

 
Reply With Quote
 
Gregor Horvath
Guest
Posts: n/a
 
      12-19-2004
chris wrote:
> I'm creating an excel document dynamically from scratch using Python
> and the win32com module. All is well, but now I need to add a macro to
> the spreadsheet and run it (to enable some sorting features in the
> spreadsheet). I think I know how to run a macro once it's installed
> (using the Run method of the excel application object...I think), but I
> can't figure out how to "install" the VBA macro code into the
> spreadsheet to begin with from my Python script.
> Any tips appreciated.


Make a xla in Excel including your VBA macro first and then create your
spreadshet from python using that xla as template.

--
Greg

 
Reply With Quote
 
Harald Massa
Guest
Posts: n/a
 
      12-19-2004
chris,

> I'm creating an excel document dynamically from scratch using Python
> and the win32com module. All is well, but now I need to add a macro to
> the spreadsheet and run it (to enable some sorting features in the
> spreadsheet).


I recommend to create the excel document not from scratch but from a
template.

I learned from experience that it is speadier to have all the static parts
allready prepared - and especially diagrams and macros are MUCH easier to
handle if allready in the programm

Harald
 
Reply With Quote
 
chris
Guest
Posts: n/a
 
      12-20-2004
This makes sense. Thanks for the ideas.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
macros-loop? calling macros X times? Andrew Arro C Programming 2 07-24-2004 09:52 AM
Explanation of macros; Haskell macros mike420@ziplip.com Python 80 11-07-2003 02:22 AM
Re: Explanation of macros; Haskell macros Michael T. Babcock Python 0 11-03-2003 01:54 PM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 5 11-01-2003 01:09 AM
Re: Explanation of macros; Haskell macros mike420@ziplip.com Python 1 10-07-2003 04:07 PM



Advertisments