Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Where can i find positions.exe file
Message
From
01/11/2000 06:22:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
31/10/2000 17:06:56
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00436523
Message ID:
00436605
Views:
22
>Thanks Cetin.
>I am working in VFP app that manage about 5000 primary merge file, and one secondary merge file. The user select an option and begin the mail merge. All the documents file has one insertion field and x asks. I can open the primary and secondary file but when i need the merge nothing happend.
>
>You Wrotte :
>
>Wordbasic PEMs are defined in wrdbasic.hlp located in winword directory. This help file contains the arguments as named arguments which are not suitable for calling via VFP. In files section there is a file called "positions.exe". It contains the "position.hlp" which in turn contains the correct argument positions suitable to pass as a parameter from VFP.
>
>my code is this
>
>PUBLIC oWordDocument
>
>*** set the LOCALEID to English
>nlLocaleId=sys(3004) && Save local id
>=sys(3006,1033) && We will be sending instructions in English
>wait window nowait "Creating Word Document..."
>oWordDocument=createobject("word.basic")
>with oWordDocument
>.appshow
>.FileOpen(cFullName)
>.MailMergeOpenDataSource(cSecFile)
>.MailMergeEditMainDocument
>.MailMerge
>endwith
>**** Set the LocaleId to the previous value
>=sys(3006,val(nlLocaleId))

Byron,
Yes this looks like what I wrote long long ago. If this is as is what I wrote then sorry there is a typo. Last .Mailmerge should be either .MailMergeToDoc or .MailMergeToPrinter. OTOH if word is not a version older than word97 using new object model is better. In files\classes section also there is a 'Mailmerge class'. Check that. Actually I myself dropped using OpenDataSource method for some weirdnesses in MDAC 2.1 and later. Instead I now lowlevel write a tab delimited file with headers, open in word, convert to table and saveas a word doc (mergedoc). Then open main document and set saved doc as a merge source :
WAIT window nowait "Creating Word Document.Please wait..."
* Word constants header file
#include "wdconst.h"
#DEFINE NL chr(13)
#DEFINE TABULATE chr(9)

* VFP3-5
lcSamplesPath = home()+"samples"
* VFP6
*lcSamplesPath = _samples
* Copy VFP data to clipboard
SELECT * from (lcSamplesPath+"\data\employee") where Title like  "%Sale%" into table Tempreport
lnFields=_CopyDataToClipBoard("Tempreport","first_name,last_name,title,hire_date,notes")

*** set the LOCALEID to English
nlLocaleId=sys(3004)  && Save local id
=sys(3006,1033)       && We will be sending instructions in English
*** set the LOCALEID to English
PUBLIC oWordDocument
oWordDocument=createobject("word.application")	&& Create word object
WITH oWordDocument
  .documents.add	&& New file
  *  .Application.DefaultTableSeparator = "~"
  WITH .ActiveDocument
    .PageSetup.Orientation = wdOrientLandscape  && Set to landscape
    .Range.Paste      && Paste VFP data
    .Range.ConvertToTable(wdSeparateByTabs,,lnFields,,wdTableFormatContemporary,,,,,,,,,.f.) && Convert to table
    .Range.Find.Execute("~",,,,,,,,,"^p",wdReplaceAll) && Restore memo para marks
  ENDWITH
  =_SampleMerge(.f.) && Do mailmerge to a new doc
  .ActiveDocument.MailMerge.Destination = wdSendToNewDocument
  .ActiveDocument.MailMerge.Execute
*    .ActiveDocument.PrintOut(.t.) && Alternative printing from form letters
*!*	  .ActiveDocument.Range.Find.Execute("^b",,,,,,,,,"^p^p[End of Merge]^p",wdReplaceAll) && Replace section breaks with para marks
  .visible = .t.  && Show word app
  .Activate  && Make it the active foreground app
ENDWITH
WAIT clear
**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))


*******************************************************************
* Insert a table in Word at specified bookmark - NonODBC safe way
*******************************************************************
FUNCTION _CopyDataToClipBoard
LPARAMETERS tcTableName, tcFieldList

lcOldAlias = Alias()  && Save alias
SELECT &tcFieldList ;
  from (tcTableName) ;
  nofilter into cursor crsTemp  && Select recs into a cursor
IF reccount("crsTemp")=0
  USE in "crsTemp"
  RETURN
ENDIF
SELECT crsTemp
lnFields = fcount()
lcTempFileName = "X"+sys(2015)+".tmp"
handle = fcreate(lcTempFileName)  && Create a temp file
&& Write header line
FOR ix = 1 to lnFields
  =fwrite(handle, field(ix))
  IF ix < lnFields
    =fwrite(handle, TABULATE)
  ENDIF
ENDFOR
=fwrite(handle, NL)
SCAN    && Start scan..endscan
  FOR ix = 1 to lnFields
    =fwrite(handle, TypeConvert(ix) ) && Write converting all to char type
    IF ix < lnFields
      =fwrite(handle, TABULATE)
    ENDIF
  ENDFOR
  =fwrite(handle, NL)
ENDSCAN
lnSize=fseek(handle,0,2)
=fseek(handle,0,0)
_CLIPTEXT = fread(handle, lnSize)  && Read file to clipboard
=fclose(handle)
ERASE (lcTempFileName)
* Prepare text copied to clipboard in VFP which is much faster than Word OLE

USE in "crsTemp"
IF !empty(lcOldAlias)
  SELECT (lcOldAlias)
ENDIF
RETURN lnFields

FUNCTION TypeConvert && Convert VFP data types to char
LPARAMETERS tnField
lcType = type(field(ix))
luValue = iif(lcType='G','',eval(field(ix)))
DO case
  CASE lcType = "D"
    lcValue = dtoc(luValue)
  CASE lcType = "T"
    lcValue = ttoc(luValue)
  CASE lcType = "N"
    lcValue = padl(luValue,20," ")
  CASE lcType = "L"
    lcValue = iif(luValue,"Yes","No")
  CASE lcType $ "M" && Replace paragraph marks with "~"
    lcValue = strtran(luValue, chr(13)+chr(10), "~")
  CASE lcType $ "C"
    lcValue = luValue
  OTHERWISE
    lcValue = ""
ENDCASE
RETURN alltrim(lcValue)

FUNCTION _SampleMerge
LPARAMETERS tlToPrinter
WITH oWordDocument
  lcTempDataDoc = sys(5)+curdir()+"T"+sys(2015)+".doc"
  WITH .ActiveDocument
    .SaveAs(lcTempDataDoc)  && Save as a word doc for mailmerge - datasource
    .Close(wdSaveChanges)   && Close saving
  ENDWITH

  .documents.add  && New file or open a template
  WITH .ActiveDocument.MailMerge
    .OpenDataSource(lcTempDataDoc) && Set saved file as data source for mailmerge (Directly a table could be set via ODBC)
    .EditMainDocument	&& Activate the main document
  ENDWITH
  .Application.Selection.TypeText("Dear,"+chr(13))
  with .Application.Selection.Font
  	.Name = 'Times New Roman'
  	.Italic = .t.
  	.Size = 14
  endwith
  .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "LAST_NAME")
  .Application.Selection.TypeText(", ")
  .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "FIRST_NAME")
  with .Application.Selection.Font
  	.Italic = .f.
  	.Name = 'Arial'
  	.Size = 10
  endwith
  .Application.Selection.TypeText(chr(13)+"Here is your notes data :"+chr(13)+chr(13))
  with .Application.Selection.Font
  	.Bold = .t.
  	.Color = rgb(0,0,255)
  endwith
  .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "NOTES")
  with .Application.Selection.Font
  	.Bold = .f.
  	.Color = rgb(0,0,0)
  endwith
  .Application.Selection.TypeText(chr(13)+chr(13)+"As to our records you were hired on ")
  with .Application.Selection.Font
  	.Color = rgb(255,0,0)
  endwith
  .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "HIRE_DATE")
  with .Application.Selection.Font
  	.Color = rgb(0,0,0)
  endwith
  .Application.Selection.TypeText(" with title [")
  .ActiveDocument.MailMerge.Fields.Add(.Application.Selection.Range, "TITLE")
  .Application.Selection.TypeText("]"+chr(13)+"Thanks"+chr(13)+"Yours Sincerely."+chr(13)+"Blah blah...")
  *!*	  WITH .ActiveDocument
  *!*	    .Close(wdDoNotSaveChanges)			&& Close w/o saving
  *!*	  ENDWITH
  IF tlToPrinter
    .Application.Options.PrintBackGround = .t.
    .ActiveDocument.MailMerge.Destination = wdSendToPrinter
    .ActiveDocument.MailMerge.Execute

* This part should be moved to a timer for async operations with some modification
    *!*	    	do while .Application.BackgroundPrintingStatus > 0 && Wait printing to finish
    *!*	    	enddo
    *!*	    	for each oDoc in .Documents
    *!*	    		oDoc.Close(wdDoNotSaveChanges)
    *!*	    	endfor
    *!*	    	oDoc = .null.
  ENDIF
ENDWITH
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform