Selasa, 24 Juni 2025

Cara cepat mengubah rumus/formula menjadi nilai/value di Excel menggunakan Macro

 Kode Macro :

Sub ConvertFormulasToValuesAndSaveToNewFolder()
    Dim sourceFolder As String, targetFolder As String
    Dim fileName As String
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim fDialog As FileDialog

    ' Pilih folder sumber
    Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
    MsgBox "Pilih folder SUMBER (berisi file Excel yang akan dikonversi)."
    If fDialog.Show <> -1 Then Exit Sub
    sourceFolder = fDialog.SelectedItems(1) & "\"

    ' Pilih folder tujuan
    MsgBox "Pilih folder TUJUAN (untuk menyimpan hasil konversi)."
    If fDialog.Show <> -1 Then Exit Sub
    targetFolder = fDialog.SelectedItems(1) & "\"

    ' Nonaktifkan notifikasi
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    ' Proses semua file Excel
    fileName = Dir(sourceFolder & "*.xls*")
    Do While fileName <> ""
        Set wb = Workbooks.Open(sourceFolder & fileName)

        ' Ubah semua worksheet jadi value-only
        For Each ws In wb.Worksheets
            With ws.UsedRange
                .Value = .Value
            End With
        Next ws

        ' Simpan dengan nama yang sama ke folder tujuan
        wb.SaveAs Filename:=targetFolder & fileName, FileFormat:=xlOpenXMLWorkbook
        wb.Close SaveChanges:=False
        fileName = Dir
    Loop

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

    MsgBox "Selesai! Semua file disimpan sebagai nilai saja ke folder tujuan.", vbInformation
End Sub


Cara pakai :

  1. Tekan Alt + F11 → buka Visual Basic Editor
  2. Pilih InsertModulepaste kode di atas
  3. Jalankan makro: ConvertFormulasToValuesAndSaveToNewFolder
  4. Pilih folder sumber (file Excel dengan formula)
  5. Pilih folder tujuan (untuk menyimpan hasil)
  6. File akan dikonversi ke nilai-only dan disimpan ke folder tujuan dengan nama yang sama

Senin, 02 Juni 2025

Mail Merge Word ke Banyak File PDF Menggunakan Macro

 Cara Super Cepat :

  • Salin skrip Macro di bawah dan tambahkan ke Word.
  • Tambahkan kolom berikut ke data Excel Surat Anda: DocFolderPath, DocFileName, PdfFolderPath, PdfFileName.
  • Pada kolom DocFileName & PdfFileName, masukkan nama file yang Anda inginkan untuk Dokumen Word yang dipisahkan dan PDF yang dikonversi. Tidak perlu menyertakan ekstensi.
  • Di bidang DocFolderPath, masukkan jalur folder yang valid (misalnya C:\Users\me\Documents\docx). Jalur ini dapat sama untuk semua baris, atau berbeda – pilihan ada di tangan Anda.
  • Di bidang PdfFolderPath, masukkan jalur folder yang valid (misalnya C:\Users\me\Documents\pdf). Jalur ini dapat sama untuk semua baris, atau berbeda – pilihan ada di tangan Anda.
  • Buat Gabungan Surat Anda.
  • Jalankan Makro dari MS Word
  • Duduk santai dan biarkan komputer bekerja, akan lebih baik jika settingan Power Off pada komputer / laptop di-nonaktifkan agar seluruh file anda dapat selesai meskipun memakan waktu pemrosesan yang cukup lama.
Skrip Macro :

Sub MailMergeToPdfBasic()                                                        ' Mark the start of the Subroutine (i.e. Macro) and name it "MailMergeToPdf"
' Macro created by Imnoss Ltd
' Please share freely while retaining attribution
' Last Updated 2021-05-03
    Dim masterDoc As Document, singleDoc As Document, lastRecordNum As Long   ' Create variables ("Post-it Notes") for later use
    Set masterDoc = ActiveDocument                                               ' Identify the ActiveDocument (foremost doc when Macro run) as "masterDoc"

    masterDoc.MailMerge.DataSource.ActiveRecord = wdLastRecord                   ' jump to the last active record (active = ticked in edit recipients)
    lastRecordNum = masterDoc.MailMerge.DataSource.ActiveRecord                  ' retrieve the record number of the last active record so we know when to stop

    masterDoc.MailMerge.DataSource.ActiveRecord = wdFirstRecord                  ' jump to the first active record (active = ticked in edit recipients)
    Do While lastRecordNum > 0                                                   ' create a loop, lastRecordNum is used to end the loop by setting to zero (see below)
        masterDoc.MailMerge.Destination = wdSendToNewDocument                    ' Identify that we are creating a word docx (and no e.g. an email)
        masterDoc.MailMerge.DataSource.FirstRecord = masterDoc.MailMerge.DataSource.ActiveRecord              ' Limit the selection to just one document by setting the start ...
        masterDoc.MailMerge.DataSource.LastRecord = masterDoc.MailMerge.DataSource.ActiveRecord               ' ... and end points to the active record
        masterDoc.MailMerge.Execute False                                        ' run the MailMerge based on the above settings (i.e. for one record)
        Set singleDoc = ActiveDocument                                           ' Identify the ActiveDocument (foremost doc after running the MailMerge) as "singleDoc"
        singleDoc.SaveAs2 _
            FileName:=masterDoc.MailMerge.DataSource.DataFields("DocFolderPath").Value & Application.PathSeparator & _
                masterDoc.MailMerge.DataSource.DataFields("DocFileName").Value & ".docx", _
            FileFormat:=wdFormatXMLDocument                                      ' Save "singleDoc" as a word docx with the details provided in the DocFolderPath and DocFileName fields in the MailMerge data
        singleDoc.ExportAsFixedFormat _
            OutputFileName:=masterDoc.MailMerge.DataSource.DataFields("PdfFolderPath").Value & Application.PathSeparator & _
                masterDoc.MailMerge.DataSource.DataFields("PdfFileName").Value & ".pdf", _
            ExportFormat:=wdExportFormatPDF                                      ' Export "singleDoc" as a PDF with the details provided in the PdfFolderPath and PdfFileName fields in the MailMerge data
        singleDoc.Close False                                                    ' Close "singleDoc", the variable "singleDoc" can now be used for the next record when created
        If masterDoc.MailMerge.DataSource.ActiveRecord >= lastRecordNum Then     ' test if we have just created a document for the last record
            lastRecordNum = 0                                                    ' if so we set lastRecordNum to zero to indicate that the loop should end
        Else
            masterDoc.MailMerge.DataSource.ActiveRecord = wdNextRecord           ' otherwise go to the next active record
        End If

    Loop                                                                         ' loop back to the Do start
End Sub                                                                          ' Mark the end of the Subroutine




Sumber : https://imnoss.com/word-mail-merge-to-separate-pdfs/