View Single Post
  #4   Report Post  
Posted to microsoft.public.word.mailmerge.fields,microsoft.public.word.vba.general
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Automating Word 2007 mail merge?

Hi Alicia,

Please send to files to me at



Remove the ( ) from around the @
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alicia" wrote in message
...
Macro is run from the STDLTR.DOT. It is called from EMPTY.DOC using
PEN_RPT.doc as the output template. If you have somewhere I can send the
3
files, I'd be glad to send all of them to you. I can also send you a
mocked
up (can't send real data from site) .cfg & data input files.

Thank you,

================================================== ====
' 11/19/02 - Alicia Lee (E0091159) - Modified to run via PIA on the
' Web - added code to read a configuration file for the report input and
output
' names and locations

'global variables
Dim letter_out As String 'Letter output name (PASOF01_PID)
Dim pen_rpt_ltrfile As Variant 'variable used to check if the
input file exists
Dim pen_rpt_filename As String 'fully qualified report name for
Letter Template
Dim pen_rpt_filesave As String 'fully qualified merged letter
document name
Dim pen_rpt_letter As String 'Name of the Letter Template
Dim pen_rpt_runlocation As String 'Location of WinWord mail merge
template
Dim pen_rpt_data As String 'Input data file name
Dim pen_rpt_outputlocation As String 'Directory location for the
output
Sub Main()

'if there is an error during the processing, go to the Errmsg function
On Error GoTo Errmsg

'open the configuration file to get the report input/output information
Open "c:\ps\PEN_RPT.cfg" For Input As #2

' Read configuration data into variables
'letter name (pen_rpt_letter), Location of WinWord mail merge template
(pen_rpt_runlocation),
'input data location (pen_rpt_data), merged letter output location
(pen_rpt_outputlocation),
'and merged letter file name (letter_out)
Input #2, pen_rpt_letter, pen_rpt_runlocation, pen_rpt_data,
pen_rpt_outputlocation, letter_out

'change to the directory the input data is located
ChangeFileOpenDirectory "c:\ps"

'verify the input data file exists
pen_rpt_ltrfile = Dir(pen_rpt_data)

If pen_rpt_ltrfile = "" Then
'exit if there is no input data file
Application.Quit SaveChanges:=wdDoNotSaveChanges
Else
'build the fully qualified report name
pen_rpt_filename = pen_rpt_runlocation + "\" + pen_rpt_letter +
".DOC"
'open the input datafile
Documents.Open pen_rpt_filename, , ReadOnly, , , , , , , , , True
'make the letter document the active document
pen_rpt_filename = ActiveDocument.Name
'start the mail merge process
ActiveDocument.MailMerge.OpenDataSource pen_rpt_ltrfile, , ,
ReadOnly

With ActiveDocument.MailMerge
'send the merged data to a new document
.Destination = wdSendToNewDocument
.Execute
End With

'set the merged letter document name
pen_rpt_filesave = pen_rpt_outputlocation + "\" + letter_out +
".doc"

'save the merged letter
ActiveDocument.SaveAs pen_rpt_filesave
'close all open documents
Documents.Close wdDoNotSaveChanges

'close the configuration file
Close #2

'delete the input data file
'Kill pen_rpt_data

'delete the configuration file
'Kill "D:\temp\PEN_RPT.cfg"

'exit Word
Application.Quit SaveChanges:=wdDoNotSaveChanges

End If

Exit Sub

Errmsg:
WriteError Err.Number & "-" & Err.Description

End Sub

Sub WriteError(Errmsg As String)

'create the fully qualified error log file name
'pen_rpt_filename = pen_rpt_outputlocation + "\" + pen_rpt_letter +
"_error.log"
pen_rpt_filename = "c:\ps\" + pen_rpt_letter + "_error.log"

'open the error log file

'Open pen_rpt_filename For Append As #1
Open pen_rpt_filename For Append As #3

'write the error message(s)
Print #3, Date & " - " & Errmsg

'close the error message file
Close #3

End Sub



"Doug Robbins - Word MVP" wrote:

Show us the code of the macro that works in 2003

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Alicia" wrote in message
...
Cross-posting from Word Programming into Word mailmerge and fax.

"Alicia" wrote:

I am running an SQR process that generates a configuration file (text
saved
as .cfg) and a data input file (csv format) and then does a system
call
to
execute the Word 2007 mail merge process. The Word mail merge
process,
reads
the coinfguration file to determine where the input file resides, what
Word
template to use and where to write the merged output file. This
process
is
executing on a remote server and has to be invisible to the user with
no
manual intervention needed

Creating the file works but the mail merge stops (waiting for
interaction)
when it gets to the "Finalize" stage. If I connect to the server it
is
executing on and click Finalize, the process requests a "Save As"
name.
The
macros we currently have working in Word 2003, read the input
configuration
file and automatically create the file based on the name setup in the
.cfg
file. Is there a setting or something that we can set to make Word
2007
respond the same way as Word 2003.

Thanks,