Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MS WORD
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
FoxPro 2.x
Titre:
Divers
Thread ID:
00208115
Message ID:
00209514
Vues:
34
>Jose,
>
>I've been trying to get MailMerge (MM) to work using the VFP 6.0 FoxPro Foundation Classe (FFC) MailMerge, and have been able to make it work rather easily by plopping the MM class on the form and then running the form or even the app through the command window, but when I create an EXE I get a not enough memory error (I have tons of RAM memory, 96mb, and h/d free is 800mb). Have you tried to use the FFC MM? Any ideas of how MS wants the FFC to be implemented?
>
>I was intrigued by your comments on using the bookmarks, right now I've got a Word IF construct,
>{IF{MERGEFIELD wt_ltrtp}="NY30" "{INCLUDETEXT "c:\\foxdev\\analyzer50\\letters\\NY30.DOC"} {INCLUDETEXT "c:\\foxdev\\analyzer50\\letters\\FED30.DOC"}}
>
>The NY30.Doc and Fed30.doc obviously are mailmerge templates, with the fields already placed within the boilerplate text, awaiting a series of records to be merged against the appropriate document. When I use this method, if the document (NY30.DOC, for example) has a header or footer, it is not included in merged document, while the body of the text and the merged fields all appear correctly. Is there some switch I can throw to ensure the headers and footers are being included in the merged document, if the template it's based on has headers and footers? I haven't been able to find much info on the use of INCLUDETEXT.
>
>Would you mind describing in a little more detail how you would use the concept of the bookmarks as an alternative to the above method, and will it ensure the headers and footers of the template document are included in the merged doc?
>
>Sorry for the involved question, but this has stumped me for quite a while, and I'll appreciate any help you can provide.
>
>Kevin

Kevin,
I'am not using 6.0 yet, so I can't tell what the problem is. Regarding the mail merge header and footer, I can't be of much help either because I have no practical experience in this.

What I can tell you, is how I did it. So here follows my code.
LOCAL loSelect, ;
  vp_dBeg, ;
  vp_End, ;
  lnPage, ;
  oWord, ;
  lcDocPath, ;
  lcDocTemplateFr, ;
  lcDocTemplateNl, ;
  lcDocTemplateSource,;
  lcThnkName, ;
  lcDocWorking, ;
  lBackGround, ;
  lNeerlandais

#DEFINE CR CHR(13)
#DEFINE WDPAGEBREAK  7

vp_dBeg = thisform.ctlDateRange.GetDateFrom()
vp_dEnd = thisform.ctlDateRange.GetDateTo()

loSelect = CREATEOBJECT("cSelect", thisform.ThnkObj1.cAlias)
Requery()

IF _TALLY = 0
  ERRORMSG( NOTHINGTOPRINT_LOC)
  RETURN
ELSE
  lnPage = _TALLY
  REPLACE ALL cSalutationLongue WITH "" FOR ISNULL (cSalutationLongue)
ENDIF

IF PRINTSTATUS()

  lcDocPath =  LEFT( goapp.cDefaultDatabase, RAT("\", goapp.cDefaultDatabase))+ "OLEDOCS\"
  lcDocTemplateFr = lcDocPath + "REMERCIEMENT.DOC"
  lcDocTemplateNl = lcDocPath + "BEDANKT.DOC"
  lcDocTemplateSource = lcDocPath + "INFODONS.DOT"
  lcThnkName = lcDocPath + "THANKFORMS.DOC"
  lcDocWorking = lcDocPath + "Working.DOC"

  IF ! FILE( lcDocTemplateFr)
  ERRORMSG("Le fichier " + lcDocTemplateFr + " est manquant.  Veuillez le restaurer.")
    RETURN
  ENDIF

  IF ! FILE( lcDocTemplateNl)
    ERRORMSG("Le fichier " + lcDocTemplateNl + " est manquant.  Veuillez le restaurer.")
    RETURN
  ENDIF

  IF ! FILE( lcDocTemplateSource)
    ERRORMSG("Le fichier " + lcDocTemplateSource + " est manquant.  Veuillez le restaurer.")
    RETURN
  ENDIF

  *-- let us instantiate Word
  WAIT WINDOW NOWAIT OPENINGWORD_LOC
  oWord = CREATEOBJECT("word.application")
  WAIT CLEAR
  *-- If it failed, bailout
  IF TYPE ("oWord") # "O"
    MESSAGEBOX("", ;
      64, "Attention")
    RETURN
  ENDIF

  *-- create an empty document based on the Infodons.DOT template
  oWord.Documents.Add(lcDocTemplateSource)
  oWord.ActiveDocument.SaveAS( lcThnkName)

  SELECT v_Remerciement
  SCAN
    *-- open an existing template document
    *-- oWord.Documents.Open(lcDocTemplate)

    DO CASE
      CASE v_Remerciement.cLangue = "Francais" ;
          OR v_Remerciement.cLangue = "Français" ;
          OR v_Remerciement.cLangue = UPPER( "Francais") ;
          OR v_Remerciement.cLangue = UPPER( "Français")
        *-- open an existing document
        oWord.Documents.Open(lcDocTemplateFr)
        Thisform.cLabel2.Caption = "Préparation remerciement " + ;
          ALLTRIM( v_Remerciement.cNom1) + " en " + ALLTRIM( v_Remerciement.cLangue)+"."
      CASE v_Remerciement.cLangue = "Néerlandais" ;
          OR v_Remerciement.cLangue = "Neerlandais" ;
          OR v_Remerciement.cLangue = UPPER("Néerlandais") ;
          OR v_Remerciement.cLangue = UPPER("Neerlandais")
        lNeerlandais = .T.
        oWord.Documents.Open(lcDocTemplateNl)
        Thisform.cLabel2.Caption =  "Préparation remerciement " + ;
          ALLTRIM( v_Remerciement.cNom1) + " en " + ALLTRIM( v_Remerciement.cLangue)+"."
      OTHERWISE
        Thisform.cLabel2.Caption = ""
        ERRORMSG( "Remerciement " + ALLTRIM( v_Remerciement.cNom1) + " demandé en " + ;
          ALLTRIM( v_Remerciement.cLangue)+ ;
          ".  Pas de remerciement disponible dans cette langue!  Il sera émis en Français.")
        *-- open an existing document
        oWord.Documents.Open(lcDocTemplateFr)
        Thisform.cLabel2.Caption = "Préparation remerciement " + ;
          ALLTRIM( v_Remerciement.cNom1) + " en Français."
    ENDCASE 

    *-- avoid harmering REMERCIEMENT.DOC if any problem
    oWord.ActiveDocument.SaveAS(lcDocWorking)
    
    oWord.ActiveDocument.Bookmarks("cSalutationLongue").range.text = ALLTRIM( v_Remerciement.cSalutationLongue)
    oWord.ActiveDocument.Bookmarks("cPrenom").range.text = ALLTRIM( v_Remerciement.cPrenom)
    oWord.ActiveDocument.Bookmarks("cNom1").range.text = ALLTRIM( v_Remerciement.cNom1)
    oWord.ActiveDocument.Bookmarks("cNom2").range.text = ALLTRIM( v_Remerciement.cNom2)
    oWord.ActiveDocument.Bookmarks("cAdresse").range.text =  ;
      IIF( ! EMPTY (v_Remerciement.cAdresse1), ALLTRIM( v_Remerciement.cAdresse1)+ " ", "") + ;
      IIF( ! EMPTY( v_Remerciement.cAdresse2), ALLTRIM( v_Remerciement.cAdresse2)+ " ", "") + ;
      ALLTRIM( v_Remerciement.cNumero)
    oWord.ActiveDocument.Bookmarks("cZip").range.text = ALLTRIM( v_Remerciement.cZip)
    oWord.ActiveDocument.Bookmarks("cLocalite").range.text = ALLTRIM( v_Remerciement.cLocalite)
    oWord.ActiveDocument.Bookmarks("cPays").range.text = ALLTRIM( v_Remerciement.cPays)
    oWord.ActiveDocument.Bookmarks("cAssocLocalite").range.text = ALLTRIM( v_Remerciement.cAssocLocalite)
    oWord.ActiveDocument.Bookmarks("cSalutationLongue2").range.text = ALLTRIM( v_Remerciement.cSalutationLongue)
    oWord.ActiveDocument.Bookmarks("cDon").range.text = ALLTRIM( v_Remerciement.cDon)
    oWord.ActiveDocument.Bookmarks("cCurrency").range.text = ALLTRIM( v_Remerciement.cCurrency)
    oWord.ActiveDocument.Bookmarks("dVersement").range.text = v_Remerciement.dVersement
    IF v_Remerciement.lAtt
     IF ! lNeerlandais
     oWord.ActiveDocument.Bookmarks("cAtt").range.text= "Votre versement, éventuellement cumulé à d'autres que vous "+ ;
       "auriez effectué ou effectuerez dans le courant de cette année fera l'objet d'une attestation fiscale pour l'année civile " + ;
       v_Remerciement.cYear + " qui vous sera expédiée dans le courant du 1er trimestre de l'an prochain."
     ELSE
       oWord.ActiveDocument.Bookmarks("cAtt").range.text= "Zelfde liedeje"
     ENDIF
    ELSE
     IF ! lNeerlandais
     oWord.ActiveDocument.Bookmarks("cAtt").range.text= "Conformément à votre souhait, ce versement ne fera pas l'objet "+;
       "d'une attestation fiscale."
     ELSE
       oWord.ActiveDocument.Bookmarks("cAtt").range.text= "Zelfde Liedje"
     ENDIF
    ENDIF
    oWord.ActiveDocument.Bookmarks("cSalutationLongue3").range.text = ALLTRIM( v_Remerciement.cSalutationLongue)
    oWord.ActiveDocument.Bookmarks("cAssocPresident").range.text = ALLTRIM( v_Remerciement.cAssocPresident)
    oWord.ActiveDocument.Bookmarks("Remerciement").range.copy

    oWord.ActiveDocument.Close()
   
    *-- Select attform.doc and paste content
    oWord.Documents(lcThnkName).Activate
    oWord.Selection.InsertParagraphAfter()
    oWord.Selection.paste()
    oWord.Selection.InsertBreak( WDPAGEBREAK)

  ENDSCAN

  oWord.ActiveDocument.Save()

  IF YESNO( "Vos remerciements sont sauvegardés dans le fichier " + lcThnkName + " au format Word. " + ;
      "Souhaitez-vous les imprimer maitenant?")

    WITH oWord
      *-- temporarily disable background printing, since it will generate a
      *-- dialog because word would quit while Word is printing in background...
      lBackGround = .Options.PrintBackGround
      IF lBackGround
        .Options.PrintBackGround = .F.
      ENDIF
      .ActiveDocument.Printout()
      WAIT WINDOW NOWAIT PRINTINGNOW_LOC
      IF lBackGround
        .Options.PrintBackGround = ! .Options.PrintBackGround
      ENDIF
    ENDWITH

  ENDIF

  WAIT WINDOW NOWAIT CLOSINGWORD_LOC
  oWord.Quit()
  oWord = .NULL.
  Release oWord

ELSE
  =MESSAGEBOX(PRINTERNOTREADY_LOC, MB_ICONEXCLAMATION)
ENDIF
In Word you can have embedded bookmarks. That's the case of "Remerciement" that takes all the text from the first line to the very last.

Hope this helps.


José
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform