Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create Letter routine with variables
Message
From
20/05/2005 09:30:36
 
 
To
20/05/2005 08:08:14
Stephen Hunt
Admit Computer Services Inc.
Farmingdale, New York, United States
General information
Forum:
Visual FoxPro
Category:
Third party products
Miscellaneous
Thread ID:
01016151
Message ID:
01016176
Views:
10
Hi Stephen,

I tried the mailmerge route and got fed up with problems with datasources. It turned out to be much easier to just automate it myself. Here's some code I used:
#DEFINE wdStory 6
#DEFINE wdpagebreak 7
#DEFINE wdLine 5

* --- look for Word Template
IF FILE(m.lcTemplate)

   LOCAL loWord AS WORD.APPLICATION
   * --- try to start Word
   WAIT WINDOW NOWAIT 'Starting Microsoft Word.'

   TRY        
      loWord = CREATEOBJECT("word.application")
      WAIT WINDOW NOWAIT 'Creating Word document. Please wait.'
      loDocOutPut = loWord.Documents.Add()
      m.lnRecCount = 0
      SCAN 
         m.lnRecCount = m.lnRecCount + 1 
         loDoc = loWord.Documents.Add(FULLPATH(m.lcTemplate))
         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('myTable' + 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._OutputFile)
      loWord.Selection.HomeKey(wdStory)
      loWord.visible = .T.
      WAIT CLEAR 

   CATCH TO loError
      MESSAGEBOX( TRANSFORM(loError.Errorno) + ":" + loError.message )
      loWord.Quit
       
      RELEASE loWord
      
   ENDTRY 

ELSE
   MESSAGEBOX( 'The Word mail merge file ' + m.lcTemplate + ' could not be found. Inform System Manager.')
ENDIF
>I am desiging a new product that needs to give the user the ability to create a letter template and allow for the user to insert variables who's source comes from a table. I know Word has a mail merge function built into
>it, is there anyway I can use this capability in my VFP app or are there any third party products that could provide this functionality ?
>
>Thanks For Your Help !
>Stephen J. Hunt
Frank.

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

Click here to load this message in the networking platform