Python as VBA replacement under Windows?

W

Wolfgang Keller

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
 
T

Thomas Bartkus

Wolfgang Keller said:
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

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

Wolfgang Keller

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

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.
Rather - VBA is bundled and integrated with MS Office in order to manipulate
COM. You can use Python to do that too!

Yup, from outside. What I would like to do is do it from "inside" the
application.
"perfectly possible"?

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
 
T

Thomas Bartkus

Wolfgang Keller said:
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.

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.
Yup, from outside. What I would like to do is do it from "inside" the
application.

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top