0% found this document useful (0 votes)
74 views1 page

Convert Mailing Word Ke PDF Dengan VBA Excell

This document describes how to convert a mail merge in Microsoft Word to individual PDF files using VBA code in Excel. The code opens a Word mail merge document and Excel data source, loops through the records, saves each as a DOCX and PDF file with a unique ID, and deletes the temporary DOCX files.

Uploaded by

hendrick mj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views1 page

Convert Mailing Word Ke PDF Dengan VBA Excell

This document describes how to convert a mail merge in Microsoft Word to individual PDF files using VBA code in Excel. The code opens a Word mail merge document and Excel data source, loops through the records, saves each as a DOCX and PDF file with a unique ID, and deletes the temporary DOCX files.

Uploaded by

hendrick mj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Convert mailing word ke PDF dengan VBA Excell

Option Explicit

Const FOLDER_SAVED As String = "D:\yuhuuu\surat-"


Const SOURCE_FILE_PATH As String = "D:\yuhuuu\nilaii.xlsx"

Sub MailMergeToIndPDF()
Dim MainDoc As Document, TargetDoc As Document
Dim dbPath As String
Dim recordNumber As Long, totalRecord As Long

Set MainDoc = ActiveDocument


With MainDoc.MailMerge

'// if you want to specify your data, insert a WHERE clause in the SQL statement
.OpenDataSource Name:=SOURCE_FILE_PATH, sqlstatement:="SELECT * FROM
[Sheet1$]"

totalRecord = .DataSource.RecordCount

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 & .DataSource.DataFields("ID").Value &


".docx", wdFormatDocumentDefault
TargetDoc.ExportAsFixedFormat FOLDER_SAVED
& .DataSource.DataFields("ID").Value & ".pdf", exportformat:=wdExportFormatPDF
TargetDoc.Close 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
'with additional delete docx file

Word------ Alt F11-- Insert---Module

You might also like