Passer au contenu principal

Comment enregistrer chaque page en tant que fichiers PDF séparés dans un document Word?

Lorsque vous utilisez un document Microsoft Word, vous pouvez enregistrer chaque page en tant que fichiers PDF séparés un par un grâce à sa fonction Enregistrer sous intégrée. Cependant, si des centaines de pages doivent être divisées et enregistrées en tant que fichiers PDF individuels, comment pouvez-vous faire? Cet article fournit une méthode pour résoudre rapidement ce problème.

Enregistrez chaque page en tant que fichiers PDF séparés en vrac avec le code VBA


Enregistrez chaque page en tant que fichiers PDF séparés en vrac avec le code VBA

Le code VBA ci-dessous vous aide à enregistrer rapidement chaque page d'un document en tant que fichiers PDF individuels en même temps. Veuillez faire comme suit.

1. Ouvrez le document que vous allez enregistrer chaque page ou pages spécifiques sous forme de fichiers pdf, puis appuyez sur le bouton autre + F11 clés pour ouvrir le Microsoft Visual Basic pour applications fenêtre.

2. dans le Microsoft Visual Basic pour applications fenêtre, cliquez sur insérer > Module, copier ci-dessous le code VBA dans la fenêtre Module.

Code VBA: enregistrez chaque page en tant que fichiers PDF séparés en même temps dans un document 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. appuie sur le F5 clé pour exécuter le code.

4. dans le Explorer fenêtre, sélectionnez un dossier pour enregistrer les fichiers pdf et cliquez sur le OK bouton. Voir la capture d'écran:

5. Dans le premier Kutools for Word boîte de dialogue, entrez le numéro de page de démarrage de votre document dans la zone de texte et cliquez sur OK.

6. Dans le second Kutools for Word boîte de dialogue, entrez le dernier numéro de page de votre document, puis cliquez sur D'ACCORD. Voir capture d'écran:

Notes: Si vous souhaitez simplement enregistrer plusieurs pages en continu dans le document sous forme de fichiers PDF séparés tels que les pages 4, 5 et 6, veuillez saisir 4 et 6 séparément dans les deux boîtes de dialogue ci-dessus.

Après avoir exécuté le code, veuillez accéder au dossier spécifié que vous avez sélectionné à l'étape 4, vous pouvez voir que toutes les pages sont divisées et enregistrées en tant que fichiers PDF individuels, comme illustré ci-dessous.


Divisez et enregistrez chaque page d'un document en tant que nouveaux documents séparés:

La Diviser le document utilité de Kutools for Excel peut vous aider à diviser et enregistrer facilement chaque page du document actuel en tant que nouveau document distinct en bloc, comme illustré ci-dessous. Téléchargez et essayez-le maintenant! (60-journée sentier libre)

Meilleurs outils de productivité bureautique

Kutools for Word - Élevez votre expérience Word avec Over 100 Caractéristiques remarquables !

🤖 Assistant IA Kutools: Transformez votre écriture avec l'IA - Générer du contenu  /  Réécrire le texte  /  Résumer des documents  /  Demander des informations basé sur le document, le tout dans Word

(I.e. Maîtrise des documents: Pages divisées  /  Fusionner des documents  /  Exporter la sélection dans différents formats (PDF/TXT/DOC/HTML...)  /  Conversion par lots en PDF  /  Exporter des pages sous forme d'images  /  Imprimer plusieurs fichiers à la fois

Édition du contenu: Rechercher et remplacer par lots sur plusieurs fichiers  /  Redimensionner toutes les images  /  Transposer les lignes et les colonnes du tableau  /  Convertir le tableau en texte

🧹 Nettoyage sans effort : balayer Espaces supplémentaires  /  Sauts de section  /  Tous les en-têtes  /  Boîtes de texte  /  Liens hypertextes  / Pour plus d'outils de suppression, rendez-vous sur notre Supprimer le groupe

Insertions créatives: Insérer Mille séparateurs  /  Cases à cocher  /  Boutons radio  /  code QR  /  Code barres  /  Tableau des lignes diagonales  /  Légende de l'équation  /  Légende  /  Légende de la table  /  Plusieurs images  / Découvrez-en davantage dans le Insérer un groupe

🔍 Sélections de précision: Localiser pages spécifiques  /  les tables  /  formes  /  paragraphes de titre  / Améliorez la navigation avec PLUS Sélectionnez les fonctionnalités

Améliorations des étoiles: Naviguez rapidement vers n’importe quel endroit  /  insertion automatique de texte répétitif  /  basculer de manière transparente entre les fenêtres de document  /  11 outils de conversion

👉 Vous voulez essayer ces fonctionnalités ? Kutools for Word propose un Essai gratuit 60-day, sans aucune limite ! 🚀
 
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