Use macros in Excel via win32com

Discussion in 'Python' started by chris, Dec 19, 2004.

  1. chris

    chris Guest

    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
     
    chris, Dec 19, 2004
    #1
    1. Advertising

  2. chris

    Guest

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


    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 =---
     
    , Dec 19, 2004
    #2
    1. Advertising

  3. chris

    chris Guest

    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
     
    chris, Dec 19, 2004
    #3
  4. 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
     
    Gregor Horvath, Dec 19, 2004
    #4
  5. chris

    Harald Massa Guest

    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
     
    Harald Massa, Dec 19, 2004
    #5
  6. chris

    chris Guest

    This makes sense. Thanks for the ideas.
     
    chris, Dec 20, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    80
    Views:
    2,489
    Stephen J. Bevan
    Nov 7, 2003
  2. Replies:
    1
    Views:
    473
    Marco Antoniotti
    Oct 7, 2003
  3. Replies:
    5
    Views:
    511
  4. Michael T. Babcock

    Re: Explanation of macros; Haskell macros

    Michael T. Babcock, Nov 3, 2003, in forum: Python
    Replies:
    0
    Views:
    534
    Michael T. Babcock
    Nov 3, 2003
  5. Andrew Arro

    macros-loop? calling macros X times?

    Andrew Arro, Jul 23, 2004, in forum: C Programming
    Replies:
    2
    Views:
    513
    S.Tobias
    Jul 24, 2004
Loading...

Share This Page