I can not get this code to work correctly:
#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 1
#DEFINE wdDoNotSaveChanges 0
#DEFINE wdWindowStateMinimize 2
oWord=CREATEOBJECT("Word.Application")
oWord.VISIBLE = .F.
oWord.WindowState = wdWindowStateMinimize
oWord.Documents.Open('C:\VFP Projects\PSTek\Reports\WordMail.Doc')
nSave = oWord.ActiveDocument.MailMerge.State
IF oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
oWord.ActiveDocument.MailMerge.Destination = wdSendToPrinter
oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
oWord.ActiveDocument.MailMerge.DataSource.LastRecord = 1
oWord.ActiveDocument.MailMerge.Execute
ENDIF
oWord.Quit(wdDoNotSaveChanges)
RELEASE oWord
WAIT WINDOW nSave
nSave = 0 and it never executes the merge
If I go and run the WordMail.doc it merges fine. What in the world am I doing wrong? Why does my oWord.ActiveDocument.MailMerge.State evaluate to 0?
#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 1
#DEFINE wdDoNotSaveChanges 0
#DEFINE wdWindowStateMinimize 2
oWord=CREATEOBJECT("Word.Application")
oWord.VISIBLE = .F.
oWord.WindowState = wdWindowStateMinimize
oWord.Documents.Open('C:\VFP Projects\PSTek\Reports\WordMail.Doc')
nSave = oWord.ActiveDocument.MailMerge.State
IF oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
oWord.ActiveDocument.MailMerge.Destination = wdSendToPrinter
oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
oWord.ActiveDocument.MailMerge.DataSource.LastRecord = 1
oWord.ActiveDocument.MailMerge.Execute
ENDIF
oWord.Quit(wdDoNotSaveChanges)
RELEASE oWord
WAIT WINDOW nSave
nSave = 0 and it never executes the merge
If I go and run the WordMail.doc it merges fine. What in the world am I doing wrong? Why does my oWord.ActiveDocument.MailMerge.State evaluate to 0?