Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automating a mail merge
Message
 
To
09/02/2007 00:43:33
Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01193945
Message ID:
01194046
Views:
20
Ok, here's the code posting I promised:
n = adir(FilesArray, "*.doc")

*Just ran it on 10 docs for an initial test
for i = 1 to 10
	
	wait window "Processing " + FilesArray(i, 1) nowait
	
	FileName = FilesArray(i, 1)
	XLSFile  = forceext(FileName, "XLS")
	
	* An existing XLS file of the correct structure
	copy file msds2.xls to &XLSFile
		
	oDoc = oWord.Documents.Open(FileName)
	oDoc.MailMerge.MainDocumentType = 0
	oDoc.MailMerge.OpenDataSource(XLSFile,,,,,,,,,,,"Entire Spreadsheet",,,,8)
	
	oDoc.Save
	oDoc.Close
	
	* When used, gave "file in use" error or something similar
	* delete file &XLSFileWithPath
	
endfor
>Hi Russell
>
>You may consider something I at first didn't think would be a good thing.
>
>Create a vfp monitoring program on the client's PCs. Have the terminal server send the data to a table on the client PC. Have the client PC do the merge and printing.
>
>A terminal server trying to launch multiple instances of Word, Excel and VFP is ahem... asking for trouble. ;)
>
>>I automate Word to do mail merges for clients, but one client seems to be having some issues I normally don't see. First, they are doing a lot of initial printing and then the amount they do each day will taper off to some relatively small number between (guessing) 50 and 150 documents. This application is run under Terminal Services. There are about 390 documents and they have to be sent out to 3 or 4 thousand times intially. Printing started out fine, but the last couple of days they've run into locking problems (only one person is printing at the moment AFAIK). Each document uses the same Excel file for its data source. The data source is repopulated between each document, the document prints, the data source is repopulated, then the next document prints.
>>
>>So I thought maybe I'd use a different data source for each document. I have a program to attach a data source to a Word doc and it worked great to attach the one single data source to each document, but when attaching a different data source to each document there are problems. I've discovered that if Excel is already open when the program is run, it works much faster (60 seconds per doc when Excel is not already open and just over 5 seconds per doc when Excel is open). The problem is that altough Word did not open Excel, it did open the data source doc (the spreadsheet) and it seems it would close the data source document, too. Yet it does not and I'm left with a bunch of open Excel docs. Not that big of a deal, but I'd be left with 390 spreadsheets open in Excel and I'm not sure how my computer will handle that (can you even have that many open docs in Excel).
>>
>>Why the speed difference mentioned above and why is Word leaving the Excel spreadsheet file open? I'd post a code example, but I'm falling asleep at the keyboard. Please post any suggestions you have and I'll try to get some code out here.
eCost.com continues to rip people off
Check their rating at ResellerRatings.com
Previous
Reply
Map
View

Click here to load this message in the networking platform