Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Word Macros to VFP COM

Status
Not open for further replies.

AlanArons

Programmer
Aug 1, 2002
91
0
0
US
Does anyone know how to convert Word Macros to VFP COM. My goal is to create merge data, start Word, open the document, change the merge file to the one just created, merge the data to a new document, save the new document, then quit Word.

Thanks for your help.

Alan Arons
[ponder]
 
here is a start

tmp_file = SYS(2023)+LEFT(ALLTRIM(z_termid),8)+'.DOC'

IF create_doc(tmp_file)

xsafety = ddesetoption('SAFETY')
= ddesetoption('SAFETY', .F.)

xchannel = DDEINITIATE('Winword', 'System')
IF xchannel=-1
WAIT WINDOW NOWAIT 'Starting Word'
IF .NOT. EMPTY(xcommand)
xtesting=dos_cmd(xcommand)
IF xtesting
WAIT WINDOW NOWAIT 'Started Word'
ENDIF
ENDIF
ENDIF

xchannel = DDEINITIATE('Winword', 'System')
IF xchannel=-1
=dsp_msg('/o/l/b','Word could not be started...')
ENDIF
IF xchannel<>-1 .AND. chkcommand()
xchannel = DDEINITIATE(&quot;WinWord&quot;, &quot;System&quot;)

=DDEEXECUTE(xchannel, '[FileOpen &quot;&xdocument&quot;]')
WAIT WINDOW NOWAIT 'Opened Document'
IF RIGHT(UPPER(xdocument),3) = 'DOC' .AND. .NOT. ('/modify' $ m.p_extra)
= DDEEXECUTE(xchannel, '[MailMergeOpenDataSource &quot;&tmp_file&quot;]')
WAIT WINDOW NOWAIT 'Changed Datasource'
= DDEEXECUTE(xchannel, '[MailMergeToDoc]')
WAIT WINDOW NOWAIT 'Merged Information'
ENDIF

**'Activate the Word window so you can see the document being built
=DDEEXECUTE(xchannel, '[AppActivate &quot;Microsoft Word&quot;, 1]')
WAIT WINDOW NOWAIT 'Activated Word'

= INKEY(z_timeout,'HM')

* Close WinWord
WAIT WINDOW NOWAIT 'Closing Word'
= DDEEXECUTE(xchannel, &quot;[FileExit 2]&quot;)
= DDETERMINATE(xchannel)
ENDIF
= ddesetoption('SAFETY', xsafety)
ENDIF

 
While a number of us are familiar with VFP, you are best served by posting your question in the VFP forum forum184

In that way, more VFP specific gurus will have the chance to respond to your question and more VFP users will have the chance to benefit from the posting.

Good Luck,
JRB-Bldr
VisionQuest Consulting
Business Analyst & CIO Consulting Services
CIOServices@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top