L
love2cu2
I need to print a document using Mail Merge template to
automatically without user interacts with it. I have
some VBA to do this, except that it doesn't close the
whole word application afterwards. It just closes all
word documents.
Here is what I have:
Private Sub Document_Open()
Dim sourceDocument, activePrinter
sourceDocument = ActiveDocument.Name
'activePrinter = "\\10.200.1.3\test"
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.SuppressBlankLines = True
.Execute Pause:=True
theFileName = .DataSource.DataFields
("Firstname").Value
End With
ActiveDocument.SaveAs ("test" & theFileName)
ActiveDocument.Close
'ActiveDocument.ActiveWindow.Close
ActiveDocument.Close SaveChanges:=wsDoNotSaveChanges
End Sub
I have to close it twice because one is to close the
result document, the other is to close the template.
and another question, but not required to what I need to
do so far is how to print to a network
printer. "ActivePrinter" doesn't seem to work.
automatically without user interacts with it. I have
some VBA to do this, except that it doesn't close the
whole word application afterwards. It just closes all
word documents.
Here is what I have:
Private Sub Document_Open()
Dim sourceDocument, activePrinter
sourceDocument = ActiveDocument.Name
'activePrinter = "\\10.200.1.3\test"
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.SuppressBlankLines = True
.Execute Pause:=True
theFileName = .DataSource.DataFields
("Firstname").Value
End With
ActiveDocument.SaveAs ("test" & theFileName)
ActiveDocument.Close
'ActiveDocument.ActiveWindow.Close
ActiveDocument.Close SaveChanges:=wsDoNotSaveChanges
End Sub
I have to close it twice because one is to close the
result document, the other is to close the template.
and another question, but not required to what I need to
do so far is how to print to a network
printer. "ActivePrinter" doesn't seem to work.