Loncat ke daftar isi utama

Bagaimana cara menghitung nomor halaman file Pdf di Excel?

Jika ada beberapa file Pdf dalam folder tertentu, sekarang, Anda ingin menampilkan semua nama file ini di lembar kerja, dan mendapatkan nomor halaman dari setiap file. Bagaimana Anda bisa menangani pekerjaan ini di Excel dengan cepat dan mudah?

Hitung nomor halaman file Pdf dari folder di lembar kerja dengan kode VBA


Hitung nomor halaman file Pdf dari folder di lembar kerja dengan kode VBA

Mungkin kode VBA berikut dapat membantu Anda menampilkan semua nama file Pdf dan setiap nomor halamannya di lembar kerja, lakukan seperti ini:

1. Buka lembar kerja tempat Anda ingin mendapatkan file Pdf dan nomor halaman.

2. Tahan ALT + F11 kunci, dan itu membuka Microsoft Visual Basic untuk Aplikasi jendela.

3. Klik Menyisipkan > Modul, dan tempelkan makro berikut di file Modul Jendela.

Kode VBA: Cantumkan semua nama file Pdf dan nomor halaman di lembar kerja:

Sub Test()
    Dim I As Long
    Dim xRg As Range
    Dim xStr As String
    Dim xFd As FileDialog
    Dim xFdItem As Variant
    Dim xFileName As String
    Dim xFileNum As Long
    Dim RegExp As Object
    Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
    If xFd.Show = -1 Then
        xFdItem = xFd.SelectedItems(1) & Application.PathSeparator
        xFileName = Dir(xFdItem & "*.pdf", vbDirectory)
        Set xRg = Range("A1")
        Range("A:B").ClearContents
        Range("A1:B1").Font.Bold = True
        xRg = "File Name"
        xRg.Offset(0, 1) = "Pages"
        I = 2
        xStr = ""
        Do While xFileName <> ""
            Cells(I, 1) = xFileName
            Set RegExp = CreateObject("VBscript.RegExp")
            RegExp.Global = True
            RegExp.Pattern = "/Type\s*/Page[^s]"
            xFileNum = FreeFile
            Open (xFdItem & xFileName) For Binary As #xFileNum
                xStr = Space(LOF(xFileNum))
                Get #xFileNum, , xStr
            Close #xFileNum
            Cells(I, 2) = RegExp.Execute(xStr).Count
            I = I + 1
            xFileName = Dir
        Loop
        Columns("A:B").AutoFit
    End If
End Sub

4. Setelah menempelkan kode, lalu tekan F5 kunci untuk menjalankan kode ini, dan a Browse jendela muncul, pilih folder yang berisi file Pdf yang ingin Anda daftarkan dan hitung nomor halaman, lihat tangkapan layar:

doc menghitung halaman pdf 1

5. Dan kemudian, klik OK tombol, semua nama file Pdf dan nomor halaman tercantum ke dalam lembar kerja saat ini, lihat tangkapan layar:

doc menghitung halaman pdf 2

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
Comments (79)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Thank you so much for the code
This comment was minimized by the moderator on the site
Is it possible to have it itemize instead of group these page numbers. For example if PDF 1 has 3 pages and PDF 2 has 2 pages, how do i get it to look like this?

File Name Page
PDF 1 1
PDF 1 2
PDF 1 3
PDF 2 1
PDF 2 2
This comment was minimized by the moderator on the site
This is so amazing and helpful. Is there a way to run this in a folder that has several subfolders and do all the files at once instead of having to run it for each folder?
This comment was minimized by the moderator on the site
Hello, MWilkers

You can view this comment to solve your problem:
https://www.extendoffice.com/documents/excel/5330-excel-vba-pdf-page-count.html#comment-39782,32012,20

Please have a try.
This comment was minimized by the moderator on the site
Thank you, the code worked very well. Is it possible to get the last modified date of PDF file as well in a separate column
This comment was minimized by the moderator on the site
Thank you for the code.
This comment was minimized by the moderator on the site
Wow, this has been SO helpful to me. Thank you!
This comment was minimized by the moderator on the site
Buenas. Me funciona perfecto. Ahora lo que necesitar铆a es imprimir unas paginas en concreto y llamo a esta rutina pero no imprime el pdf sino el excel.
Sub imprimirpdf()
Dim rutaPDF As String
rutaPDF = Sheets("Hoja1").Range("D2")
F = Cells(2, 7)
T = Cells(2, 8)
pid = Shell("C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe " & Chr(34) & rutaPDF & Chr(34))
ActiveSheet.PrintOut From:=F, To:=T
DoEvents 'Paso 5 - Esperar que se Imprima el PDF
hnd = OpenProcess(PROCESS_TERMINATE, True, pid) 'Paso 6 - Obtener el handle(manejador) del proceso(Adobe Reader)
TerminateProcess hnd, 0 '
End Sub
This comment was minimized by the moderator on the site
Hallo vielen Dank f眉r den Code und die super Erkl盲rung
Ich habe nun das Problem das meine PDF-Dateien zwei unterschiedliche Seitengr枚脽e (A4 und A6) inne haben.
Nun w眉rde ich gerne Pro PDF diese unterschied zus盲tzlich auslesen k枚nnen.
Habe Sie hierf眉r vielleicht eine L枚sung.

Gerne k枚nnen sie mich auch unter email: erreichen.

MFG,
Sebastian
This comment was minimized by the moderator on the site
I get 0 pages for most pdfs, help?
This comment was minimized by the moderator on the site
Hello, MAXMAN
Could you upload the PDF file which can't get the correct number here? Or you can send your PDF file to my email: .
So that we can check the problem.
Thank you!
This comment was minimized by the moderator on the site
thanks
but i get an error runtime error "52" bad file name or number
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
Rate this post:
0   Characters
Suggested Locations