By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

Where is Word - COM solution

P: n/a
Hi all,

This goes back to my previous post called "Where is Word". In short, I
wanted to make a temporary file (directory listing), open it in Word to let
the user edit, layout and print it, and then delete the temp file
afterwards.

I almost got it to work without using COM, but there was a problem when the
user runs the script a second time without closing Word after the first
time. In that case, the temp file could not be deleted (see original post).

Luckily, the following code was provided to me by a good fellow named
Hughes, Chad O. Thanks again for your time and effort on this, Chad!
<code>
import os
from win32com.client import Dispatch

dirlist = os.listdir(os.getcwd())

word = Dispatch('Word.Application')
word.Documents.Add(Visible = True)
word.Visible = True

for line in dirlist:
word.Selection.TypeText(line + '\r\n')
</code>
So the questions 'where is Word' and 'how to delete the temp file' have
become obsolete. Nice, eh? COM rules!

Cheers,
g


Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.