Yes, the .dot document is the mail merge main document. I want to do a
mail
merge to a new document, print the new document, save the new document
without the macro and close all documents. This is the entire code:
Private Sub Document_New()
' open letter document
On Error GoTo Err_New
ActiveDocument.MailMerge.OpenDataSource Name:="", ConfirmConversions:=
_
False, ReadOnly:=False, linktosource:=True, addtorecentfiles:=False, _
passworddocument:="", passwordtemplate:="", writepassworddocument:="",
_
writepasswordtemplate:="", revert:=False, Format:=wdOpenFormatAuto, _
connection:="DSN=SchoolTRAX;DATABASE=SDGStudent;" _
, sqlstatement:= _
"SELECT * FROM [STUDENT_S_LETTER_FETCH]", sqlstatement1:=""
Dim doc1, doc2
Set doc1 = ActiveDocument
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=True
End With
Set doc2 = ActiveDocument
ActiveDocument.SaveAs ("C:\Program Files\SD&G
Ltd\SchoolTRAX\Reports\TempReport.doc")
ActiveDocument.PrintOut
ActiveDocument.Close
doc1.Close wdDoNotSaveChanges
Exit_New:
Exit Sub
Err_New:
If Err.Number <> 0 And Err.Number <> 4198 Then
msg = "error # " & Str(Err.Number) & "was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "error", Err.HelpFile, Err.HelpContext
Debug.Print Error(Err.Number)
End If
Resume Exit_New
End Sub
Thanks.
Karin
Doug Robbins - Word MVP said:
Is the .dot document the mail merge main document?
How are you creating the ActiveDocument?
What else does your code do? There is no reason to use a macro to do
just
what the code that you posted does.
--
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, originally posted via msnews.microsoft.com
My VBA code is in a .dot document. In the code I am saying:
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.MailAsAttachment = False
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute pause:=True
End With
Sorry, I am not sure how to change it to do what you are suggesting.
:
Save your mailmerge main document as a template and use File>New and
select
that template as the basis of the mail merge main document that you
want
to
use, then execute the mail merge from that new document.
--
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, originally posted via msnews.microsoft.com
I am running a mail merge macro that sends the merged document to a
new
document. I then do a save as to save the new document. The problem
is
that
it is also saving the macro with the new document. How can I save
the
new
document without the macro in it?
Thanks for your help.
Karin