469,356 Members | 2,055 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

Connect to VBA Objects?

Hi,
I wonder if Python can connect to the object models exposed by Excel or
Word.
Thanks in advance,
Ken Hutson
San Antonio, Texas
Jul 18 '05 #1
4 2708
On Monday 22 September 2003 07:38 pm, Kenneth Hutson wrote:
Hi,
I wonder if Python can connect to the object models exposed by Excel or
Word.
Thanks in advance,
Ken Hutson
San Antonio, Texas


Yep, assuming you have the win32all extensions installed:

from win32com.client import Dispatch
d = Dispatch('Word.Application')
d.Visible = 1
....

-Dave

Jul 18 '05 #2
Kenneth Hutson wrote:

I wonder if Python can connect to the object models exposed by Excel or
Word.


Yes it can, using the win32all extensions by Mark Hammond. Check the
archives for various examples, or consider buying the book on the subject:
http://www.amazon.com/exec/obidos/tg...glance&s=books

-Peter
Jul 18 '05 #3
Many thanks to Bob Gailer, Dave Brueck and Peter Hansen.
Kenneth Hutson
San Antonio, Texas

"Kenneth Hutson" <hu*******@ev1.net> wrote in message
news:vm************@corp.supernews.com...
Hi,
I wonder if Python can connect to the object models exposed by Excel or
Word.
Thanks in advance,
Ken Hutson
San Antonio, Texas

Jul 18 '05 #4
At 07:38 PM 9/22/2003, Kenneth Hutson wrote:
Hi,
I wonder if Python can connect to the object models exposed by Excel or Word.


Use Mark Hammond's win32all.
http://starship.python.net/crew/mham...Downloads.html

import win32com.client
app = win32com.client.Dispatch("word.application")
app.visible = 1
documents = self.app.Documents
doc = documents.Add("c:\\foo.doc")

etc.

app = win32com.client.Dispatch("excel.application")
app.visible = 1
app.WorkBooks.Open("c:\\foo.xls")

etc.

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.506 / Virus Database: 303 - Release Date: 8/1/2003

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by T. Wintershoven | last post: by
11 posts views Thread by Marcus | last post: by
2 posts views Thread by Cornelius.Eckhoff | last post: by
3 posts views Thread by cberthu | last post: by
2 posts views Thread by Steve | last post: by
reply views Thread by =?Utf-8?B?dG9t?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.