PDA

View Full Version : VBA WORD Mailmerge unwanted dialog box "Do you want to save the changes"



pjr2006
02-18-2009, 05:15 PM
I have spent the last few hours scanning possible questions/solutions. I guess this has been answered previously but I cannot find it

My situation

Pick database running AccuTerm emulation allows scripting
Word Form Letter created with MailMerge function
Tab delimited .txt file created for data, filename matches the mailmerge document, data alters
Single Letter per .txt file, several data fields
User wants to be able to edit document before printing

The process basically works. However WORD prompts
"Do you want to save the changes you have made to Form letter ?"
Operator needs to reply "Y"es then "C"ancel Save as dialog box before editting is possible

Is there a way to
1. Set the Word Form letter so that this dialog box doesn't appear
2. Pass an argument in the script associated with the Open and/or MailMerge to suppress the dialog box(es)
3. Add code to the script to automate the "Yes" then "Cancel" keyboard input

Subroutine as a non-VBA user appears pretty straight-forward. This may be the problem - too simple

SUBROUTINE ATWORDMERGE(DOCUMENT,MERGEDATA)
* pjr 11/02/09 - PO Confirmation Letter requires WORD to open and allow modification of the Merge Document
*
*DOCUMENT = 'S:\Fly Buys Merge\Fly Buys Letter.doc'
*MERGEDATA = 'T:\flybuys.csv'
* DOCUMENT = 'C:\Conf_Letter.doc'
* MERGEDATA = 'C:\Conf_Letter.txt'
*
* THIS SUBROUTINE EXECUTES A PRESET WORD MERGE WITH A DOCUMENT
* Pass path to template document in DOCUMENT, path to merge data * file in MERGEDATA.
*
EQU ESC TO CHAR(27), STX TO CHAR(2), CR TO CHAR(13), EM TO CHAR(25)
*First create our object variables
SCR = 'Dim WordApp As Object'
SCR = SCR:EM:'Dim WordDoc As Object'
*Make sure errors dont mess us up
SCR = SCR:EM:'On Error Resume Next'
*Start up word
SCR = SCR:EM:'Set WordApp = CreateObject("Word.Application")'
*Open our source document
SCR = SCR:EM:'Set WordDoc = WordApp.Documents.Open (FileName:="':DOCUMENT:'", ReadOnly:=True)'
*Merge the document with our data file
SCR = SCR:EM:'With WordDoc.MailMerge'
SCR = SCR:EM:' .OpenDataSource Name:= "':MERGEDATA:'"'
SCR = SCR:EM:' .SuppressBlankLines = True'
SCR = SCR:EM:' .Execute Pause:=True'
SCR = SCR:EM:'End With'
*That should do it. The only thing left is clean up. This is very important
*If we don't close both the document and the application, it will stay
*in memory. If you try to run the macro twice, it will fail because
*the document is already open in another session. It also
*uses up memory
SCR = SCR:EM:' WordDoc.Close savechanges:=False'
SCR = SCR:EM:' Set WordDoc = Nothing'
SCR = SCR:EM:' WordApp.Quit'
SCR = SCR:EM:' Set WordApp = Nothing'
PRINT ESC:STX:'P':SCR:CR:
RETURN

Thanks in advance for any light shone on this problem

Regards
Peter Robertson