Hi,
The code attached is used for performing a mail merge (which it does) by creating a document and closes the source/template document.
What code can I add to close and save the merged document in read only in word or even better in pdf ?
Will greatly appreciate your help. Thank you
The code attached is used for performing a mail merge (which it does) by creating a document and closes the source/template document.
What code can I add to close and save the merged document in read only in word or even better in pdf ?
Will greatly appreciate your help. Thank you
Private Sub LFD10_letter()
Dim oMainDoc As Word.Document
Dim oSel As Word.Selection
Dim sDBPath As String
If oApp Is Nothing Then
Set oApp = CreateObject("Word.Application")
End If
Set oMainDoc = oApp.Documents.Open("C:\Documents and Settings\Chris\Desktop\Letter_Access\60D")
oApp.Visible = True 'set connection as visible
With oMainDoc.MailMerge
.MainDocumentType = wdFormLetters
sDBPath = "C:\Documents and Settings\Chris\My Documents\db2.mdb"
.OpenDataSource Name:=sDBPath, _
SQLStatement:="SELECT * FROM `" & "LFD10" & "`", SQLStatement1:="" 'link to data source
End With
With oMainDoc
.MailMerge.Destination = wdSendToNewDocument
.MailMerge.Execute
' .SaveAs "LFD10" _
' & "_" & Format(Date, "ddmmyyyy") & "_" & Format(Time, "mmhhss")
oMainDoc.Close (0)
End With
oApp.Activate
oApp.Documents.Parent.Visible = True
oApp.Application.WindowState = wdWindowStateMaximize
oApp.ActiveWindow.WindowState = wdWindowStateNormal
oApp.Quit (0)
End Sub