Option Explicit
Const FOLDER_SAVED As String = "D:\Test\" 'sesuaikan direktorinya
Const SOURCE_FILE_PATH As String = "D:\Test\[Link]" 'sesuaikan direktorinya
Sub MailMergeToIndPDF()
Dim MainDoc As Document, TargetDoc As Document
Dim dbPath As String
Dim recordNumber As Long, totalRecord As Long
Set MainDoc = ActiveDocument
With [Link]
'// if you want to specify your data, insert a WHERE clause in the SQL statement
.OpenDataSource Name:=SOURCE_FILE_PATH, sqlstatement:="SELECT * FROM [Olah$]"
totalRecord = .[Link]
For recordNumber = 1 To totalRecord
With .DataSource
.ActiveRecord = recordNumber
.FirstRecord = recordNumber
.LastRecord = recordNumber
End With
.Destination = wdSendToNewDocument
.Execute False
Set TargetDoc = ActiveDocument
TargetDoc.SaveAs2 FOLDER_SAVED & .[Link]("Nama").Value & ".docx",
wdFormatDocumentDefault 'sesuaikan dengan field yang akan dijadikan format penamaan
[Link] FOLDER_SAVED & .[Link]("Nama").Value &
".pdf", exportformat:=wdExportFormatPDF 'sesuaikan dengan field yang akan dijadikan format
penamaan
[Link] False
Set TargetDoc = Nothing
Next recordNumber
End With
On Error Resume Next
Kill FOLDER_SAVED & "*.docx"
On Error GoTo 0
Set MainDoc = Nothing
End Sub
'adopted from [Link]
with-word-vba/
'with additional delete docx file