Vai al contenuto principale

Come salvare ogni pagina come file PDF separati in un documento di Word?

Durante l'utilizzo del documento Microsoft Word, è possibile salvare ogni pagina come file PDF separati uno per uno con la sua funzione Salva con nome incorporata. Tuttavia, se ci sono centinaia di pagine che devono essere divise e salvate come singoli file pdf, come puoi fare? Questo articolo fornisce un metodo per risolvere rapidamente questo problema.

Salva ogni pagina come file PDF separati in blocco con il codice VBA


Salva ogni pagina come file PDF separati in blocco con il codice VBA

Il codice VBA sottostante ti aiuta a salvare rapidamente ogni pagina in un documento come singoli file pdf allo stesso tempo. Si prega di fare quanto segue.

1. Apri il documento in cui salverai ogni pagina o pagine specifiche come file pdf, quindi premi il tasto altro + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare clic inserire > Modulo, copia sotto il codice VBA nella finestra del modulo.

Codice VBA: salva ogni pagina come file PDF separati contemporaneamente in un documento Word

Sub SaveAsSeparatePDFs()
'Updated by Extendoffice 20180906
    Dim I As Long
    Dim xStr As String
    Dim xPathStr As Variant
    Dim xDictoryStr As String
    Dim xFileDlg As FileDialog
    Dim xStartPage, xEndPage As Long
    Dim xStartPageStr, xEndPageStr As String
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xFileDlg.Show <> -1 Then
        MsgBox "Please chose a valid directory", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    xPathStr = xFileDlg.SelectedItems(1)
    xStartPageStr = InputBox("Begin saving PDFs starting with page __? " & vbNewLine & "(ex: 1)", "Kutools for Word")
    xEndPageStr = InputBox("Save PDFs until page __?" & vbNewLine & "(ex: 7)", "Kutools for Word")
    If Not (IsNumeric(xStartPageStr) And IsNumeric(xEndPageStr)) Then
        MsgBox "The enterng start page and end page should be number format", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    xStartPage = CInt(xStartPageStr)
    xEndPage = CInt(xEndPageStr)
    If xStartPage > xEndPage Then
        MsgBox "The start page number can't be larger than end page", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    If xEndPage > ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) Then
        xEndPage = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
    End If
    For I = xStartPage To xEndPage
        ActiveDocument.ExportAsFixedFormat xPathStr & "\Page_" & I & ".pdf", _
        wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportFromTo, I, I, wdExportDocumentWithMarkup, _
        False, False, wdExportCreateHeadingBookmarks, True, False, False
    Next
End Sub

3. premi il F5 chiave per eseguire il codice.

4. Nel Scopri la nostra gamma di prodotti selezionare una cartella in cui salvare i file pdf e fare clic su OK pulsante. Vedi screenshot:

5. Nella prima Kutools for Word finestra di dialogo, immettere il numero di pagina iniziale del documento nella casella di testo e fare clic OK.

6. Nella seconda Kutools for Word finestra di dialogo, immettere il numero dell'ultima pagina del documento, quindi fare clic su OK. Visualizza gli screenshot:

Note:: Se vuoi solo salvare diverse pagine continue nel documento come file pdf separati come le pagine 4, 5 e 6, inserisci 4 e 6 separatamente nelle due finestre di dialogo sopra.

Dopo aver eseguito il codice, vai alla cartella specificata selezionata nel passaggio 4, puoi vedere che tutte le pagine sono divise e salvate come singoli file pdf come mostrato nell'immagine sottostante.


Dividi e salva ogni pagina di un documento come nuovi documenti separati:

Le Documento diviso utilità di Kutools for Excel può aiutarti a dividere e salvare facilmente ogni pagina del documento corrente come nuovo documento separato in blocco come mostrato nell'immagine sottostante. Scaricalo e provalo ora! (60-giorni di percorso gratuito)

I migliori strumenti per la produttività in ufficio

Kutools for Word - Migliora la tua esperienza con le parole con Over 100 Caratteristiche notevoli!

🤖 Assistente AI di Kutools: Trasforma la tua scrittura con l'intelligenza artificiale - Genera contenuto  /  Riscrivere il testo  /  Riepilogare i documenti  /  Richiedi informazioni sulla base del documento, tutto all'interno di Word

📘 Padronanza dei documenti: Pagine divise  /  Unisci documenti  /  Esporta la selezione in vari formati (PDF/TXT/DOC/HTML...)  /  Converti in batch in PDF  /  Esporta pagine come immagini  /  Stampa più file contemporaneamente...

Modifica dei contenuti: Trova e sostituisci in batch su più file  /  Ridimensiona tutte le immagini  /  Trasporre righe e colonne della tabella  /  Converti tabella in testo...

🧹 Pulito senza sforzo: Spazza via Spazi extra  /  Interruzioni di sezione  /  Tutte le intestazioni  /  Caselle di testo  /  Collegamenti ipertestuali  / Per ulteriori strumenti di rimozione, vai al nostro Rimuovi gruppo...

Inserti creativi: Inserisci Mille separatori  /  Caselle di controllo  /  Pulsanti di scelta  /  QR Code  /  Codice a barre  /  Tabella della linea diagonale  /  Didascalia dell'equazione  /  Didascalia immagine  /  Didascalia  /  Immagini multiple  / Scopri di più nella Inserisci gruppo...

???? Selezioni di precisione: Individuare pagine specifiche  /  con tabelle  /  forme  /  paragrafi di intestazione  / Migliora la navigazione con Scopri di più Seleziona funzionalità...

Miglioramenti delle stelle: Naviga rapidamente verso qualsiasi luogo  /  inserire automaticamente testo ripetitivo  /  passare senza problemi da una finestra all'altra del documento  /  11 strumenti di conversione...

👉 Vuoi provare queste funzionalità? Kutools per Word offre a Prova gratuita 60-day, senza limitazioni! 🚀
 
Comments (26)
Rated 5 out of 5 · 3 ratings
This comment was minimized by the moderator on the site
How to set output File Name base on footer each page?
This comment was minimized by the moderator on the site
Hello,

I was wondering if there was a way to have it pull the name for the PDF from the word doc. Example: instead of Page_01, have a pull an account number that was the 3rd line down in the word document?
This comment was minimized by the moderator on the site
Hi
what if I need to set specific name for each splited PDF.
This should be taken from WORD text - it is serial korespondece- all pages have same format
Can you advise?
This comment was minimized by the moderator on the site
Hi, how would you save each pdf page as a name that can be found from within each word page being exported?
This comment was minimized by the moderator on the site
Hi, how will change the code for mac os?
This comment was minimized by the moderator on the site
Is there a way to save per 2 pages?

Ex. save page 1/2 in Page_1.pdf
save page 3/4 in Page_2.pdf

Thanks!
This comment was minimized by the moderator on the site
im wondering the same thing! please help!
This comment was minimized by the moderator on the site
Wondering the same
This comment was minimized by the moderator on the site
10x :) this was realy helpful!!!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Thanks for this, this is great. i was wondering if you have a way of naming my pdf files differently per each extract not only Page_1.pdf.

Thanks
This comment was minimized by the moderator on the site
Hi samir,
How would you like to name these pdf files? Please give me an example.
This comment was minimized by the moderator on the site
Like saving each document with a different name, not just Page_1.pdf and so on.
This comment was minimized by the moderator on the site
Hi Camila,
The following VBA code can help you solve the problem.
Note: You need to specify a different name in this line: xFileName = "AA; BB; CC; DD". Here AA, BB and CC are the names for the PDF files.
Please change them to meet your needs. You can add more names and separate them by semicolon. To mention that the number of names specified must match the number of pages you expored. And the PDF files will be named in order of the specified names in the code.
Sub SaveAsSeparatePDFs()
'Updated by Extendoffice 20221223
    Dim xStr As String
    Dim xPathStr As Variant
    Dim xDictoryStr As String
    Dim xFileDlg As FileDialog
    Dim xStartPage, xEndPage As Long
    Dim xStartPageStr, xEndPageStr As String
    Dim xFileName As String
    Dim xNameArr() As String

    xFileName = "AA; BB; CC; DD"  'Specify a name for each page. The number of names specified must match the number of pages you exported.The PDF files will be named in order of the the specified names
    xNameArr = VBA.Split(xFileName, ";")
    Set xFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    If xFileDlg.Show <> -1 Then
        MsgBox "Please chose a valid directory", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    xPathStr = xFileDlg.SelectedItems(1)
    xStartPageStr = InputBox("Begin saving PDFs starting with page __? " & vbNewLine & "(ex: 1)", "Kutools for Word")
    xEndPageStr = InputBox("Save PDFs until page __?" & vbNewLine & "(ex: 7)", "Kutools for Word")
    If Not (IsNumeric(xStartPageStr) And IsNumeric(xEndPageStr)) Then
        MsgBox "The enterng start page and end page should be number format", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    xStartPage = CInt(xStartPageStr)
    xEndPage = CInt(xEndPageStr)
    If xStartPage > xEndPage Then
        MsgBox "The start page number can't be larger than end page", vbInformation, "Kutools for Word"
        Exit Sub
    End If
    If xEndPage > ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) Then
        xEndPage = ActiveDocument.BuiltInDocumentProperties(wdPropertyPages)
    End If
    For I = xStartPage To xEndPage
        ActiveDocument.ExportAsFixedFormat xPathStr & "\" & VBA.Trim(xNameArr(I - 1)) & ".pdf", _
        wdExportFormatPDF, False, wdExportOptimizeForPrint, wdExportFromTo, I, I, wdExportDocumentWithMarkup, _
        False, False, wdExportCreateHeadingBookmarks, True, False, False
    Next
    Erase xNameArr
End Sub
This comment was minimized by the moderator on the site
Добрый день!
Есть ли возможность сохранить из ворд файла(используя слияние) в пдф файл - Решения собственников на общее собрание.
При этом учитываем, что PDF должен сохраняться так: в 1 файле должно быть несколько листов (1 квартира), по данному модулю страницы сохраняются в пдф, но раздельно
This comment was minimized by the moderator on the site
Hi,
Sorry I don't understand what you mean. You may need to attach a screenshot or a sample file to describe the problem you encountered more clearly.
This comment was minimized by the moderator on the site
Thanks for the script, it has also saved me a lot of work in exporting pages as pdf!
Rated 5 out of 5
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