Re: Calling Excel module functions from python [repost]

Discussion in 'Python' started by Mark Carter, Jul 10, 2003.

  1. Mark Carter

    Mark Carter Guest

    Koczian <-Augsburg.de> wrote in message news:<bejgq8$9j8$-augsburg.de>...
    > Mark Carter schrieb:
    >
    > > In Excel, I have a module named modCSV which has a function named
    > > SaveSheet(), which I want to be able to call from python. How do I do
    > > it?
    > >
    > > I've opened the workbook containing the module, and executed the code:
    > >
    > > from win32com.client import Dispatch
    > > xlApp = Dispatch("Excel.Application")
    > > xlApp.Visible = 1
    > > wb = xlApp.ActiveWorkbook
    > > wbc = wb.VBProject.VBComponents("modCSV")
    > > wbc.SaveSheet()
    > >
    > > but I get the error message:

    [snip]

    > Try
    >
    > xlApp.Run('SaveSheet')


    It works!


    > That works with ordinary Excel macros, but I don't know about
    > VBProject.VBComponents. Possibly this might work:
    >
    > wbc.Run('SaveSheet').


    It doesn't work. But that doesn't matter, because the first method works.

    A further tip:
    For a function taking arguments, use
    xlApp.Run("func", "arg1", "arg2", ...)

    Thanks
    Mark Carter, Jul 10, 2003
    #1
    1. Advertising

  2. Mark Carter

    Koczian Guest

    Mark Carter schrieb:
    > A further tip:
    > For a function taking arguments, use
    > xlApp.Run("func", "arg1", "arg2", ...)
    >

    Thank you! That was something I tried to get right some weeks ago but
    gave up on. Moral: don't give up, ask around.

    Koczian

    --
    Dr. Sibylle Koczian
    Universitaetsbibliothek, Abt. Naturwiss.
    D-86135 Augsburg

    Tel.: (0821) 598-2400, Fax : (0821) 598-2410
    e-mail : -Augsburg.DE
    Koczian, Jul 11, 2003
    #2
    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:
    6
    Views:
    6,261
  2. kayakerjess
    Replies:
    0
    Views:
    318
    kayakerjess
    Sep 21, 2005
  3. kayakerjess
    Replies:
    1
    Views:
    381
    Chris Smith
    Sep 23, 2005
  4. =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=

    Problem with Excel reports ::::Excel 2003 Migration To Excel 2007

    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=, Oct 5, 2007, in forum: ASP .Net
    Replies:
    15
    Views:
    1,480
    =?Utf-8?B?c2hhc2hhbmsga3Vsa2Fybmk=?=
    Oct 24, 2007
  5. Cannonbiker

    Calling Python functions from Excel

    Cannonbiker, Nov 15, 2009, in forum: Python
    Replies:
    8
    Views:
    1,279
    Cannonbiker
    Nov 18, 2009
Loading...

Share This Page