473,666 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where is Word - COM solution

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.g etcwd())

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
0 1048

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

Similar topics

3
4317
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str' which may contain new lines and will contain html code, IN this string any "words" that begin with an underscore I want to replace with a given word. A word here being a group of chars preceded by a space or null (start of line) and closed by a...
1
2293
by: Lord Merlin | last post by:
Can someone please help me with a good swearword filter, or assist me with my current one? This is the code I have currently, but it doesn't always work. I can do the same test, with the same word 4/5/6/7 times in a row, and sometimes it works, sometimes not. ============================================================
0
1234
by: Chris J | last post by:
Hi all, ] I'm having a problem with Word 2002 when downloading a Word document with IE6. This is in an intranet application, and the download occurs through an ASP that does security checks (amongst other things) before passing the document back to the client. What seems to be happening is that, when the ASP sets a content-type of
4
8872
by: Tom Dauria | last post by:
I have an application that will be distributed remotely. In the Access application I am opening Word documents and mail merging. The Word documents are linked to a tmpLetter table. In my code I write the records to be merged into that table. The Word documents are using a system dsn (ODBC) to connect to the data source. In my code I simply open the Word documents after writing to the table do a mail merge and print. It runs pretty...
6
1732
by: Simon | last post by:
on my frmCustomer form i would like a button that open up words and runs a mail merger only with the data on on that form ( as on the mail merger i just want the customer address for when i write a personal letter to that customer only) I know how to put a button to open a run a mail merger but i do not know how to only make it mail merger the customer details on that form and no other customers..
1
13088
by: xavier vazquez | last post by:
I have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the other....how i can fix this the program look like this import java.util.ArrayList; import java.util.Random;
0
2013
by: xavier vazquez | last post by:
have a problem with a program that does not working properly...when the program run is suppose to generate a cross word puzzle , when the outcome show the letter of the words overlap one intop of the other....how i can fix this this run the random words for the program import javax.swing.JOptionPane; import java.util.ArrayList; import java.util.Random; public class CrossWordPuzzleTester {
6
8643
by: Justin | last post by:
Hi all, i need some help over here... i found the solution to export file from mysql db into *.csv. but is there anyway to convert the contents into *.doc and save in my webserver and providing a link for the end users to download the word file? FYI, the database records are obtained by end users submitting the forms themselve and i saved it in my db... Thanx.
0
7784
by: PracticalApps | last post by:
I looked to find a canned solution to create a Word document in my application and just couldn't find anything that just gets to the point. I would think, and I may be making too strong of an assumption here, that anyone looking for this kind of solution would just want a simple example that they can work from and expand upon. In my case, I just want to output a new Word document. I found that creating a simple wrapper class would make this...
0
8640
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...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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
5664
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
4198
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
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
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
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.