#nama #sertifikat #otomatis
Di video kali ini saya membagikan tips cara menginput nama pada sertifikat menggunakan Microsoft Word, mengambil data dari Excel.
Berikut Script Code QUERY yang digunakan :
Option Explicit
Const FOLDER_SAVED As String = "D:\TUTORIAL\PART1\Surat Tugas-" 'sesuaikan direktorinya
Const SOURCE_FILE_PATH As String = "D:\TUTORIAL\PART1\database.xlsx" '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 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("Nama").Value & ".docx", wdFormatDocumentDefault 'sesuaikan dengan field yang akan dijadikan format penamaan
TargetDoc.ExportAsFixedFormat FOLDER_SAVED & .DataSource.DataFields("Nama").Value & ".pdf", exportformat:=wdExportFormatPDF 'sesuaikan dengan field yang akan dijadikan format penamaan
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
'adopted from [ Ссылка ]
'with additional delete docx file
Ещё видео!