473,657 Members | 2,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Office COM automatisation - calling python from VBA

Hi all,

I am trying to write some code (macro's, if you like) to glue together
our Office applications (mainly Word, Excel and Outlook). We have a lot
of different projects going on simultaneously. The idea is to develop a
centralized framework (starting point, common interface) for my users
to view/control their documents/correspondence, on a per project basis.

As an example, I'd like to have a control (button, menu entry) in
Outlook that allows my users to bring up, say, an email for a certain
contact (architect, owner, engineer, ..) on a certain project, with
certain attachments, .. Currently, I have a 'public folder' in OL
(Exchange) that reflects our project structure.

I'll be using COM, and I could probably make an application that
controls Outlook (externally). But I'd also like to have this
functionality exposed in OL itself. So I guess I'll need to use VBA,
but I don't really like VBA - relax, please, it's just an opinion.. ;)

So, ideally, I'd like to program as much as possible in python (I'm
pretty new to that, too, btw), and only use VBA if needed - say, to
call python objects/methods (+ wxGUI, please).
Would that be an easy, a hard, or an insane strategy? Maybe there are
some tutorials on this (searched the list, but didn't quite find any).
If anyone happens to have any xp/tips on this, please, fire away!
Best regards,
g

Jul 19 '05 #1
12 7273
Hi !
Perso, j'utilise ça (VBA) :

Sub TestPonx()
Dim oa As Object
Set oa = CreateObject("P onx.Mci")
Cells(2, 4) = oa.PRet("123+45 +6")
Set oa = Nothing
End Sub
"Ponx.Mci" est le nom du serveur COM Python
PRet() est équivalent à eval()
Michel Claveau


Jul 19 '05 #2
Can you make python into a com object? I think you can I just don't
rember. If so you want to find a page about com add-ins for office.
This is a com object that you can teach office to look for when It is
started. I wrote one in vb years ago and havn't looked back. But I
think that would be the way to go.

Jul 19 '05 #3
"guy lateur" <gu********@pan dora.be> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
Hi all,

I am trying to write some code (macro's, if you like) to glue together
our Office applications (mainly Word, Excel and Outlook). We have a lot
of different projects going on simultaneously. The idea is to develop a
centralized framework (starting point, common interface) for my users
to view/control their documents/correspondence, on a per project basis.

As an example, I'd like to have a control (button, menu entry) in
Outlook that allows my users to bring up, say, an email for a certain
contact (architect, owner, engineer, ..) on a certain project, with
certain attachments, .. Currently, I have a 'public folder' in OL
(Exchange) that reflects our project structure.

I'll be using COM, and I could probably make an application that
controls Outlook (externally). But I'd also like to have this
functionality exposed in OL itself. So I guess I'll need to use VBA,
but I don't really like VBA - relax, please, it's just an opinion.. ;)

So, ideally, I'd like to program as much as possible in python (I'm
pretty new to that, too, btw), and only use VBA if needed - say, to
call python objects/methods (+ wxGUI, please).
Would that be an easy, a hard, or an insane strategy? Maybe there are
some tutorials on this (searched the list, but didn't quite find any).
If anyone happens to have any xp/tips on this, please, fire away!


You are using Microsoft Windows.
You are trying to integrate ("glue together") Microsoft Office applications.
You want to use other Microsoft COM objects.
You want to your software to *be* a COM object ("functional ity exposed in OL
itself")
You want a robust GUI interface that has the look, feel, and fits in with,
MS Office.
You want to use --- Python ???

How, pray tell, do you add up (VBA+VBA+VBA+VB A+VBA) and have it come out
equaling Python?

Be reasonable here. You don't have to "like" VBA to see that this is the
only practical choice in this situation. Imagine if Python had a robust GUI
development system that fit right into your os platform AND was the native,
built in, macro language for the top 5 high level applications you needed to
work with. Do you think that might please a few of us here in this
particular newsgroup? This is exactly what Microsoft has with Office/VBA.

I don't particularly like VBA as a language either.
And
I don't like B. Gates
And
I may well be crazy.

Just not *that* crazy!
Thomas Bartkus

Jul 19 '05 #4
> You want to use --- Python ???

So far I haven't been informed of any serious arguments as to why I
wouldn't.

How, pray tell, do you add up (VBA+VBA+VBA+VB A+VBA) and have it come out
equaling Python?
My total was this: 57*python + wxPython.

Do you think that might please a few of us here in this
particular newsgroup?


Yes.

Jul 19 '05 #5
>>>>> "guy" == guy lateur <gu********@pan dora.be> writes:

guy> Hi all, I am trying to write some code (macro's, if you like)
guy> to glue together our Office applications (mainly Word, Excel
guy> and Outlook). We have a lot of different projects going on
guy> simultaneously. The idea is to develop a centralized
guy> framework (starting point, common interface) for my users to
guy> view/control their documents/correspondence, on a per project
guy> basis.

guy> As an example, I'd like to have a control (button, menu
guy> entry) in Outlook that allows my users to bring up, say, an
guy> email for a certain contact (architect, owner, engineer, ..)
guy> on a certain project, with certain attachments, .. Currently,
guy> I have a 'public folder' in OL (Exchange) that reflects our
guy> project structure.

guy> I'll be using COM, and I could probably make an application
guy> that controls Outlook (externally). But I'd also like to have
guy> this functionality exposed in OL itself. So I guess I'll need
guy> to use VBA, but I don't really like VBA - relax, please, it's
guy> just an opinion.. ;)

guy> So, ideally, I'd like to program as much as possible in
guy> python (I'm pretty new to that, too, btw), and only use VBA
guy> if needed - say, to call python objects/methods (+ wxGUI,
guy> please).
guy> Would that be an easy, a hard, or an insane strategy? Maybe
guy> there are some tutorials on this (searched the list, but
guy> didn't quite find any). If anyone happens to have any
guy> xp/tips on this, please, fire away!
guy> Best regards, g

You can have VBA code invoke a python script asynchronously without
much trouble.
If you peruse MSDN, you can find some examples that will let you have
VBA block while waiting on a python script.
Serious interaction? I'd probably persue VisualStudio and IronPython,
if ActiveState's PythonWin isn't going to be enough.
Maybe PythonWin can make Python a COM server; never researched it.
Hope these ideas help,
Chris
Jul 19 '05 #6
guy lateur wrote:
So, ideally, I'd like to program as much as possible in python (I'm
pretty new to that, too, btw), and only use VBA if needed - say, to
call python objects/methods (+ wxGUI, please).


If you are new to Python and want to use it with COM, definitely get
yourself a copy of _Python Programming on Win32_ by Mark Hammond and
Andy Robinson.

Read the first few chapters to get yourself started, then ask more
specific questions here. There always seem to be lots of helpful answers.

Good luck!

Steve P.
Jul 19 '05 #7
On 6/25/05, Stephen Prinster <pr******@mail. com> wrote:
guy lateur wrote:

If you are new to Python and want to use it with COM, definitely get
yourself a copy of _Python Programming on Win32_ by Mark Hammond and
Andy Robinson.


....or at least read the chapter available online:
http://www.oreilly.com/catalog/pytho...pter/ch12.html

It has an example of VBA / PythonCOM interaction.

- kv
Jul 19 '05 #8
Hi guy,
I'll be using COM, and I could probably make an application that
controls Outlook (externally). But I'd also like to have this
functionality exposed in OL itself. So I guess I'll need to use VBA,
but I don't really like VBA - relax, please, it's just an opinion.. ;)

So, ideally, I'd like to program as much as possible in python (I'm
pretty new to that, too, btw), and only use VBA if needed - say, to
call python objects/methods (+ wxGUI, please).

You could try to do an addin/addon for Word, Excel, and Outlook. You
don't need to code with VBA. Here you just need a language from where
you can access the microsoft interop assemblies (ie: C++ or C#;
IronPython maybe?)

I'm now working in an addon for Visio, but I'm not using python. I'm
using C#. The main idea is that we have an exe application, which
creates a COM object, with the first running instance of visio (if some
is found). Then, I use a class (event handler) to catch some events
comming from visio (this is in part documented at the msdn). I even
embebbed a windows form in Visio (it was an example in the sdk).

So, I think in theory, you could do the same with python. I have heard
you can somehow create COM objects there. You could also try the new
version of python for net: IronPython. I guess you can from there access
all the assemblies to interact with office:

Microsoft.Offic e.Interop.Excel ,
Microsoft.Offic e.Interop.Word, and
Microsoft.Offic e.Interop.Outlo ok

A good start is to see the SDK documentation of each office product you
need at each developer center in www.msdn.microsoft.com

Good luck,
Josef

Jul 19 '05 #9
On 6/25/05, Josef Meile <jm****@hotmail .com> wrote:
You could try to do an addin/addon for Word, Excel, and Outlook. You
don't need to code with VBA. Here you just need a language from where
you can access the microsoft interop assemblies (ie: C++ or C#;
IronPython maybe?)


Hmm... Why jump through .NET hoops when all you need is COM? I suppose
msoffice interops are no different than other .NET interops, which are
just that - .NET/COM interoperabilit y layer. There's no need for them
unless you're calling COM from .NET.
For CPython win32com should be enough.

- kv
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
9400
by: Oleg Konovalov | last post by:
Hi, I am writing a Java application which among many other things has to call some MS Office internal methods, which only seems to be possible from either VBA or C#. Can anybody suggest a way of Java calling VBA or C# ? I do know how to call an executable from Java or Java interface with C/C++ through JNI.
1
1584
by: Wayne Aprato | last post by:
I'm calling the following code from my autoexec macro: Application.Assistant.Visible=False but the Office Assistant still graces the screen. What am I doing wrong? Thanks in advance.
2
1749
by: Stefan Hirtbach | last post by:
Hi, I have to create and edit Excel and Word files with an server-side applikation. One problem is that on this server no Office will be accessible, so that I can't use normal automatisation. The second problem is that this files should be version independant (as far as possible. At least Office 2000, XP and 2003 must be supported but 97 is also requested). Googeling around I found that there's something called OWC. Might this be the...
1
11556
by: webstuff | last post by:
Hi, I'm getting a 'Type mismatch' exception when calling the Word.Application.Documents.Open method when using the Office XP 2003 PIAs. the actual error is: System.Runtime.InteropServices.COMException (0x80020005): Type mismatch. This method works when using the Office XP PIAs (not that this fact is
5
3612
by: John | last post by:
Hi I need to call methods from office apps from my vb.net app. Some of my clients are still on office 2000 so to maintain compatibility I can not use office 2003 PIA. Can I avoid the whole PIA route by using late binding? Could someone please give me an example of using late binding for calling office apps? Thanks
5
1555
by: sajin | last post by:
Hi all, I'am trying to create object of Excel and powerpoint through my VB.Net 2005 application. When user close the excel or powerpoint it's instance remains in the task manager. I used ReleaseComObject because of which excel instance now goes trough task manager , but same dosen't work with the Powerpoint object. Any solution? - Thanks
1
1358
by: tubby | last post by:
How are Python users dealing with some of the new OASIS Open Document formats (Open Office) or MS Open XML formats. These formats store data in a file which is actual a zip archive that contains numerous files and folders. For example, a file saved from Open Office 2.0 named 'test.odt' can be unzipped into many parts... content.xml, meta.xml, settings.xml, etc, etc. How can I read these files do re searching and matching on them, etc?...
16
3776
by: Jaco Naude | last post by:
Hi there, This is my first post over here and I hope someone can give me some guidance. I'm trying to embed Python into a Visual C++ 2008 application and I'm getting linker problems. I've compiled a DLL of the Python source code using the pythoncode VC++ project in the PCbuild folder of the source download and this works 100% without any warnings etc. I've done this in Debug and Release mode without any problems.
9
3328
by: Marco Bizzarri | last post by:
On Wed, Sep 10, 2008 at 10:04 PM, Greg Lindstrom <gslindstrom@gmail.comwrote: Ciao, Greg. you should check with the openoffice.org mailing list; I think what you are looking for is the api mailing list for openoffice; you could try to get the OpenOffice.org developers guide and the SDK, and check it (but it is not a little work) Regards
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.