file dengan ekstensi .docx, .doc, dan .rtf sekaligus ke pdf
Jika Anda ingin mengonversi banyak file extension doc, docx, rtf ke PDF sekaligus menggunakan makro di Microsoft Word, Anda bisa menggunakan kode VBA. Berikut adalah langkah-langkahnya:
Buka Microsoft Word dan pastikan tab “Developer” sudah aktif. Jika belum, aktifkan melalui File > Options > Customize Ribbon dan centang “Developer”.
Buka Editor VBA dengan menekan
Alt + F11.Buat Modul Baru:
- Klik pada proyek “Normal”.
- Pilih Insert > Module.
Tempelkan Kode Makro berikut ke dalam modul:
Sub BatchConvertDocToPDF()
Dim objWord As Object
Dim objDoc As Object
Dim strFolder As String
Dim strFile As String
Dim strDocName As String
Dim strPDFName As String
' Set the folder path
strFolder = "C:\Path\To\Your\Word\Files\"
' Create a new Word application object
Set objWord = CreateObject("Word.Application")
objWord.Visible = False
' Loop through all Word files in the folder
strFile = Dir(strFolder & "*.docx")
Do While strFile <> ""
' Open the Word document
Set objDoc = objWord.Documents.Open(strFolder & strFile)
' Set the PDF file name
strDocName = Left(strFile, InStrRev(strFile, ".") - 1)
strPDFName = strFolder & strDocName & ".pdf"
' Export the document as PDF
objDoc.ExportAsFixedFormat _
OutputFileName:=strPDFName, _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent
' Close the Word document
objDoc.Close False
' Get the next file
strFile = Dir
Loop
' Repeat for .doc files
strFile = Dir(strFolder & "*.doc")
Do While strFile <> ""
' Open the Word document
Set objDoc = objWord.Documents.Open(strFolder & strFile)
' Set the PDF file name
strDocName = Left(strFile, InStrRev(strFile, ".") - 1)
strPDFName = strFolder & strDocName & ".pdf"
' Export the document as PDF
objDoc.ExportAsFixedFormat _
OutputFileName:=strPDFName, _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent
' Close the Word document
objDoc.Close False
' Get the next file
strFile = Dir
Loop
' Repeat for .rtf files
strFile = Dir(strFolder & "*.rtf")
Do While strFile <> ""
' Open the Word document
Set objDoc = objWord.Documents.Open(strFolder & strFile)
' Set the PDF file name
strDocName = Left(strFile, InStrRev(strFile, ".") - 1)
strPDFName = strFolder & strDocName & ".pdf"
' Export the document as PDF
objDoc.ExportAsFixedFormat _
OutputFileName:=strPDFName, _
ExportFormat:=wdExportFormatPDF, _
OpenAfterExport:=False, _
OptimizeFor:=wdExportOptimizeForPrint, _
Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent
' Close the Word document
objDoc.Close False
' Get the next file
strFile = Dir
Loop
' Quit Word application
objWord.Quit
' Clean up
Set objDoc = Nothing
Set objWord = Nothing
MsgBox "All files have been converted to PDF.", vbInformation
End Sub
- Jalankan Makro dengan menekan
F5atau melalui menu Run > Run Sub/UserForm.
Pastikan untuk mengganti C:\Path\To\Your\Word\Files\ dengan path folder yang berisi file Word Anda. Makro ini akan mengonversi semua file .docx, doc, dan rtf dalam folder tersebut menjadi PDF dan menyimpannya di lokasi yang sama.