: Q1) Can I print the document from FoxPro? In other words, can the
: operator enter the data in a data entry screen, press a Print button, and
: have the merge take place and have the output printed directly without
: going to Word and doing the merge/print from Word?
yes
: Q2) Can I store the document in a FoxPro data table (general field) and
: perform the merge/print from the document template in the FoxPro table? (I
: realize need the WinWord application needs to be accessible to the user).
yes
: Q3) If Q2 is a yes, do I need to store 2 templates for each document; one
: for Win31 and another for Win95 or can the Win95 template use a Word 6.0
: document without a translation.
yes
: Q4) I know this is a lot, but could you provide some sample code? To keep
: it simple perhaps just merging a name into a Word document with the name
: coming from FoxPro.
yes...er...I mean here's something I'm using:
&& Where Word is located
wordprogram = "C:\MSOFFICE\WINWORD\WINWORD.EXE"
&& Open Word & DDE channel to
= DDESetOption("SAFETY", .F.)
channel = DDEInitiate(wordprogram, "")
IF channel = -1 THEN
RUN /N &program
DO WHILE channel = -1
channel = DDEInitiate(wordprogram, "")
ENDDO
ENDIF
= DDEExecute(channel, "[AppMinimize]"
&& Open document
= DDEExecute(channel, '[FileOpen "'+ your_template +'"]')
&& Perform search and replace
= DDEExecute(channel,;
'[EditReplace .Find="'+ template_token +;
'", .Replace="'+ some_token_value +;
'", .MatchCase=0, .ReplaceAll]')
&& Print & Exit
= DDEExecute(channel, '[FilePrint]')
= DDEExecute(channel, '[FileExit]')
= DDETerminate(channel)