Suppress displaying of main merge document

E

ewout.boter

I have made a function to create a merged document. The merge can be
started from an application running on an iSeries server (a.k.a. AS/
400). The application first assembles some data, writes it to a comma-
separated file, and then uses a command to start Word. The -m switch
is used to automatically start a macro that will run the merge. When I
do this, the merged document is displayed on screen and can be printed
(or modified, if necessary) by the user. This is exactly what should
happen. However, the main document (the template for the merge) is
also opened. This is NOT what should happen. The user should just get
the merged document on screen. I have messed around a bit in VBA, but
I have not yet found a way to suppress the displaying of the main
document. I hope somebody can help me out!

Thanks in advance,

Ewout
 
D

Doug Robbins - Word MVP

Show us the code for your macro and we might be able to suggest how it can
be modified.

--
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
 
E

ewout.boter

The code of the macro is below. The code was to a large extent
generated when I recorded the macro.

Ewout

Sub InsurancePolicy()
'
' InsurancePolicy Macro
' Macro recorded 9/9/2008 by Boter
'
Documents.Open FileName:="\\ainl1f001\inf$\data\Development
\InsurancePolicy\InsurancePolicyTemplate.doc", ConfirmConversions _
:=False, ReadOnly:=True, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
Visible:=True

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

End Sub
 
D

Doug Robbins - Word MVP

Use

Sub InsurancePolicy()
'
' InsurancePolicy Macro
' Macro recorded 9/9/2008 by Boter
'
Dim maindoc as document
Set maindoc = Documents.Open
(FileName:="\\ainl1f001\inf$\data\Development\InsurancePolicy\InsurancePolicyTemplate.doc"
With maindoc.MailMerge
.Destination = wdSendToNewDocument
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With
maindoc.Close wdDoNotSaveChanges

End Sub


--
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

The code of the macro is below. The code was to a large extent
generated when I recorded the macro.

Ewout

Sub InsurancePolicy()
'
' InsurancePolicy Macro
' Macro recorded 9/9/2008 by Boter
'
Documents.Open FileName:="\\ainl1f001\inf$\data\Development
\InsurancePolicy\InsurancePolicyTemplate.doc", ConfirmConversions _
:=False, ReadOnly:=True, AddToRecentFiles:=False,
PasswordDocument:="", _
PasswordTemplate:="", Revert:=False,
WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto,
Visible:=True

With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=True
End With

End Sub
 
E

ewout.boter

Doug,

That worked! Although I must say that I have added two options to the
Open command: ReadOnly:=True and Visible:=False. Without the
ReadOnly:=True, a Password window was displayed. I think this is a
result of the fact hat I have protected the document with a password.
Without the Visible:=False option, the main document was visible for a
very short time. With the current version of the macro, the main
document is not displayed at all.

Many thanks for your help!

Ewout
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top