Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word 2003 Mail Merge Question
Message
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
00880795
Message ID:
00880817
Views:
28
>Hi Terry,
>
>Rather than manually connecting the data source, could they use something like:
>
>
ActiveDocument.MailMerge.DataSource.Name = "C:\MyFolder\MySpreadsheet.xls"
>from the VFP side after handing it the letter name and before merging?
>(not sure of the exact syntax of the command, but that's close)
>
>>I have a client who is now using Word 2003
>>to run VFP automated Mail Merges. They manually
>>connect the Mail Merge Data Source to the Word DOC and
>>save that connection. Next, they use VFP to call up
>>Word 2003, hand it the letter name, and tell Word to merge.
>>They are finding that Word 2003 forgets its Data Source
>>(an Excel Spreadsheet) and they have to go back into the
>>letter and reconnect to the XLS.
>>
>>How can they fix this?
>>Thanks!
>>Terry

Hi Evan,
Here is the code that I am using at present:

(The MVAR lnLastrec is handed to this routine.)
llRetVal = .T.
loWord = CREATEOBJECT("Word.Application")

* This was added to prevent the "Server threw an Exception" error
*    on some Win XP / Office XP computers.
WAIT " " TIMEOUT .8

WITH loWord
	loDocument = .Documents.Open(tcWordDoc)
	loMerge = loDocument.MailMerge
	WITH loMerge.DataSource
		.FirstRecord = 1
		.LastRecord = lnLastrec	
		* .LastRecord = 1
	ENDWITH
	WITH loMerge
		.Destination = 0
		.Execute()
	ENDWITH
	loMerge = NULL
	loDocument = NULL
ENDWITH

loWord.Visible= .T.
* Bring Word to the front.
loWord.Activate()

*		.Destination = 0   Send output to New Document.
*		.Destination = 1   Send output to Printer.

*loWord.ActiveDocument.Close(0)
*loWord.Quit()
loWord = NULL
RETURN llRetVal
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform