Little Guy wrote:
>
> I'm trying to create a Python script using win32com that creates a 
> Word 2003 document.  This will become part of a little bigger script
> for work.  After the document opens up, it is split into two columns,
> then text is pasted in, taking up both columns.  After this is done,
> I'd like to move the insertion point to the end of that page.
> ...
> I have some of the code down, but need the part that moves the
> insertion point to the end and inserts a new page as well as the
> function to print the file.
>
> Basically, this is what I have, most of which I gathered onlin:

You have the basic idea.  You just need to plow through the online samples.

> I've tried
> using VBA Macro Recorder to produce similar code in VBA but I get
> stuck when trying to port the code from VBA to Python.

Your macro does nothing other than set up the columns.  It doesn't do
the text manipulation.

> I've tried browsing Microsoft's COM Automation pages, but it feels
> like I'm looking
> for a needle in a hay stack, as the saying goes.  I suppose I could
> code this
> functionality into a VBScript file and then call it from Python, but
> I'd, much, rather
> code everything in Python.

If you are going to be doing a lot of this, then unfortunately you
really need to become an expert in looking for needles in haystacks. 
The process of coming up with Python code

This, I think, does what you were trying to do:

import win32com.client as win32
word = win32.gencache.EnsureDispatch('Word.Application')
word.Visible = True
doc = word.Documents.Add()
doc.PageSetup.TextColumns.SetCount (2)

# Paste a bunch of text.

rng = doc.Range(0,0)
rng.Text = "Lots and lots of words.  " * 200

# Collapse the range so we point at the end.

rng.Collapse( win32.constants.wdCollapseEnd)

# Insert a hard page break.

rng.InsertBreak( win32.constants.wdPageBreak )

# Insert more words.

rng.Text = "More words.  " * 30


-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to