Python as VBA replacement under Windows?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wolfgang Keller

    #1

    Python as VBA replacement under Windows?

    Hello,

    this is a potentially veeery dumb question, but:

    - If an application supports VBA as a macro language,
    - and if you can execute Python code from within a VBA script (how?)
    - and if the application exposes its VBA scripting interface through
    COM

    then it should be perfectly possible to entirely replace VBA in nearly
    all Windows applications with Python, right?

    TIA,

    sincerely,

    Wolfgang Keller


  • Thomas Bartkus

    #2
    Re: Python as VBA replacement under Windows?

    "Wolfgang Keller" <wolfgang.kelle r.nospam@gmx.de > wrote in message
    news:mn.8a917d5 881245f77.30301 @gmx.de...[color=blue]
    > Hello,
    >
    > this is a potentially veeery dumb question, but:
    >
    > - If an application supports VBA as a macro language,
    > - and if you can execute Python code from within a VBA script (how?)
    > - and if the application exposes its VBA scripting interface through
    > COM
    >
    > then it should be perfectly possible to entirely replace VBA in nearly
    > all Windows applications with Python, right?
    >
    > TIA,
    >
    > sincerely,
    >
    > Wolfgang Keller[/color]

    "perfectly possible"? Hmmmhh!

    Because the MS Office suite and a few (very few!) other applications expose
    their object models via COM, you can manipulate these programs with Python
    and other languages. No applicatoin "supports VBA as a macro language".
    Rather - VBA is bundled and integrated with MS Office in order to manipulate
    COM. You can use Python to do that too!

    However

    It is difficult to argue with the built in integrated editor/debugger behind
    Excel, Word, PowerPoint, et al with the scripts packaged seamlessly inside
    the application files. It's also difficult to argue with the myriad of
    built in VBA functions that are custom designed to ease the pain of working
    with Windows internals.

    On the other hand

    I can think of nothing that you can do with VBA but can not do with Python.
    It just takes a bit more effort and you need to know more of Windows
    internals in order to pull it off.

    "perfectly possible"?

    I'm still thinking :-)
    -Tom


    Comment

    • Wolfgang Keller

      #3
      Re: Python as VBA replacement under Windows?

      > Because the MS Office suite and a few (very few!) other applications expose[color=blue]
      > their object models via COM, you can manipulate these programs with Python
      > and other languages. No applicatoin "supports VBA as a macro language".[/color]

      What I meant was that quite a lot of Windows applications (not only MS
      Office) allow to execute VBA scripts just like "macros" from within the
      application. What I want now is to write a "dummy" VBA script
      "container" that consists of/executes Python sourcecode by calling the
      Pythonwin interpreter.
      [color=blue]
      > Rather - VBA is bundled and integrated with MS Office in order to manipulate
      > COM. You can use Python to do that too![/color]

      Yup, from outside. What I would like to do is do it from "inside" the
      application.
      [color=blue]
      > "perfectly possible"?[/color]

      Well, at least as far as there's a COM interface and for someone who
      refuses to learn VB(A) but still wants to script Windows applications.

      Sincerely,

      Wolfgang Keller


      Comment

      • Thomas Bartkus

        #4
        Re: Python as VBA replacement under Windows?


        "Wolfgang Keller" <wolfgang.kelle r.nospam@gmx.de > wrote in message
        news:mn.8bf77d5 84d2edf8b.30301 @gmx.de...[color=blue][color=green]
        > > Because the MS Office suite and a few (very few!) other applications[/color][/color]
        expose[color=blue][color=green]
        > > their object models via COM, you can manipulate these programs with[/color][/color]
        Python[color=blue][color=green]
        > > and other languages. No applicatoin "supports VBA as a macro language".[/color]
        >
        > What I meant was that quite a lot of Windows applications (not only MS
        > Office) allow to execute VBA scripts just like "macros" from within the
        > application. What I want now is to write a "dummy" VBA script
        > "container" that consists of/executes Python sourcecode by calling the
        > Pythonwin interpreter.[/color]

        I *think* you may want to approach this from the other way around. If it
        were me, I would write a Python app that initates, and maintains handles to,
        the target Windows app. The controlling Python app could then drop from
        sight and respond as necessary to events occurring within the Windows app.
        This is the way you would do it from an external VB app.
        [color=blue][color=green]
        > > Rather - VBA is bundled and integrated with MS Office in order to[/color][/color]
        manipulate[color=blue][color=green]
        > > COM. You can use Python to do that too![/color]
        >
        > Yup, from outside. What I would like to do is do it from "inside" the
        > application.[/color]

        I don't *think* this is possible. Nor do I think this is worth worrying
        about. You write VB/VBA applications to work either from the inside (in
        process) or the outside (out of process) with the former being somewhat more
        efficient. Unfortunately, this is where VBA with it's integrated editor is
        woven into the warp and woof of MS Office. You are stuck running "out of
        process" with Python. But again, I don't really see this as being worth
        worrying about.
        [color=blue][color=green]
        > > "perfectly possible"?[/color]
        >
        > Well, at least as far as there's a COM interface and for someone who
        > refuses to learn VB(A) but still wants to script Windows applications.[/color]

        I have dabbled a bit using Python to control Excel. But just a bit. It's
        just too easy to invoke VBA behind Excel and fire away - even if the
        resulting code isn't nearly so elegant! Somewhere out there, is a project to
        integrate Python into Visual Studio. Microsoft has rewritten Visual Studio
        to enable the integration of 3rd party languages. That might hold some
        promise for you although I have not been following developments here very
        closely.

        As for me - I'm sick of the directions MS is taking. I'm looking to
        Gnumeric/Python as an open source replacement to Excel/VBA :-)
        Thomas Bartkus



        Comment

        Working...