Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word mail merge headaches
Message
From
15/07/2005 17:06:43
 
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 8 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01032386
Message ID:
01033209
Views:
20
>that would be great. I am not sure if I'll have the time to change the code right now but I would be interested in how you did that.

Here's what I did:
#DEFINE wdStory 6
#DEFINE wdpagebreak 7
#DEFINE wdLine 5

LOCAL loWord AS WORD.APPLICATION
TRY                      
	loWord = CREATEOBJECT("word.application")
	loDocOutPut = loWord.Documents.Add()
	m.lnRecCount = 0
	SCAN 
	   m.lnRecCount = m.lnRecCount + 1 
	   loDoc = loWord.Documents.Add(FULLPATH(m.TemplateFileName))
	   WITH loDoc

	      * we will assume the bookmarks in the document
	      * use the names of the fields
	      FOR EACH loBookmark IN .Bookmarks
	         loRange = loBookmark.Range()
	         loRange.Text = EVALUATE('TableAlias.' + loBookmark.name)
	      ENDFOR
	      .Select
	   ENDWITH 
	   WITH loWord
	      * copy the selected text and paste into output document
	      .Selection.Copy
	      loDocOutput.Select
	      .Selection.MoveDown(wdLine,1)
	      IF m.lnRecCount > 1
	         .Selection.InsertBreak(wdPageBreak)
	      ENDIF 
	      .Selection.PasteAndFormat(0)
	      
	      loDoc.close(.F.)
	   ENDWITH 
	   
	ENDSCAN 
	loDocOutput.SaveAs(m.lOutputFile)
	loWord.Selection.HomeKey(wdStory)
	loWord.visible = .T.

CATCH TO loError
	MESSAGEBOX( TRANSFORM(loError.Errorno) + ":" + loError.message)
	m.lPrintQuerySuccess = .F.
	loWord.Quit
	 
	RELEASE loWord
	  
ENDTRY 
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform