M
malycom
Hi
Someone has very kindly helped with some code which I need to ammend in
order to be complete but I am not sure how to do it.....I have tried many
various possiblities.
First thing that happens when a certain document opens is a form appears
allowing a user to select a template.
This is the code behind one of the buttons on the form.
Private Sub CommandButton1_Click()
Word.Documents.Add Template:="G:\Template\ent_test.dot"
Me.Hide
ThisDocument.Close
Document1.Close
End Sub
This works great and opens a new document based on the template closing the
original document.
This is the code behind the template which fills certain fields with merged
data which works perfectly.
Sub AutoNew()
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:= _
"C:\ENTMRG.DBF", ConfirmConversions:=False
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute
End With
End Sub
My only problem is, once the template opens and the macro is run, although a
correct document opens, the template or at least a document called Document1
is also open. Ideally, I would like that document to close without saving
changes only leaving the document with the merged data open.
The reason why is it is giving the user to many options for confusion when
closing multiple documents.
I hope you understand what I am asking as it is not easy to explain.
Someone has very kindly helped with some code which I need to ammend in
order to be complete but I am not sure how to do it.....I have tried many
various possiblities.
First thing that happens when a certain document opens is a form appears
allowing a user to select a template.
This is the code behind one of the buttons on the form.
Private Sub CommandButton1_Click()
Word.Documents.Add Template:="G:\Template\ent_test.dot"
Me.Hide
ThisDocument.Close
Document1.Close
End Sub
This works great and opens a new document based on the template closing the
original document.
This is the code behind the template which fills certain fields with merged
data which works perfectly.
Sub AutoNew()
With ActiveDocument.MailMerge
.MainDocumentType = wdFormLetters
.OpenDataSource Name:= _
"C:\ENTMRG.DBF", ConfirmConversions:=False
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute
End With
End Sub
My only problem is, once the template opens and the macro is run, although a
correct document opens, the template or at least a document called Document1
is also open. Ideally, I would like that document to close without saving
changes only leaving the document with the merged data open.
The reason why is it is giving the user to many options for confusion when
closing multiple documents.
I hope you understand what I am asking as it is not easy to explain.