Gå til hovedindhold

Hvordan gemmes hver side som separate pdf-filer i et Word-dokument?

Mens du bruger Microsoft Word-dokument, kan du gemme hver side som separate pdf-filer en efter en med dens indbyggede Gem som-funktion. Men hvis der er hundredvis af sider, der skal opdeles og gemmes som individuelle pdf-filer, hvordan kan du gøre det? Denne artikel giver dig en metode til hurtigt at løse dette problem.

Gem hver side som separate pdf-filer i bulk med VBA-kode


Gem hver side som separate pdf-filer i bulk med VBA-kode

Nedenstående VBA-kode hjælper dig med hurtigt at gemme hver side i et dokument som individuelle pdf-filer på samme tid. Gør som følger.

1. Åbn det dokument, du vil gemme hver side eller bestemte sider som pdf-filer, og tryk derefter på andre + F11 nøgler til at åbne Microsoft Visual Basic til applikationer vindue.

2. i Microsoft Visual Basic til applikationer vindue, skal du klikke på indsatte > Modul, kopier under VBA-koden til modulvinduet.

VBA-kode: Gem hver side som separate pdf-filer på samme tid i et Word-dokument

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. Tryk på F5 nøgle for at køre koden.

4. i Gennemse vindue skal du vælge en mappe for at gemme pdf-filerne og klikke på OK knap. Se skærmbillede:

5. I den første Kutools for Word i dialogboksen, skal du indtaste dit sides startnummer i tekstboksen og klikke OK.

6. I det andet Kutools for Word i dialogboksen, skal du indtaste det sidste sidenummer i dit dokument og derefter klikke på OK. Se skærmbillede:

Bemærk: Hvis du bare vil gemme flere kontinuerlige sider i dokumentet som separate pdf-filer som side 4, 5 og 6, skal du indtaste 4 og 6 separat i de ovennævnte to dialogbokse.

Når du har kørt koden, skal du gå til den angivne mappe, du valgte i trin 4, du kan se, at alle sider er opdelt og gemt som individuelle pdf-filer som vist nedenfor.


Opdel og gem hver side i et dokument som separate nye dokumenter:

Opdel dokument nytte af Kutools til Excel kan hjælpe dig med let at opdele og gemme hver side i det aktuelle dokument som separat nyt dokument i bulk som nedenstående skærmbillede vist. Download og prøv det nu! (60-dag gratis spor)

Bedste kontorproduktivitetsværktøjer

Kutools for Word - Forøg din Word-oplevelse med Over 100 Bemærkelsesværdige funktioner!

Dyk ned i de fremhævede funktioner nedenfor eller klik her for at udforske den fulde kraft af Kutools for Word.

📘 Dokumentbeherskelse: Opdelt sider  /  Flet dokumenter  /  Eksporter udvalg i forskellige formater (PDF/TXT/DOC/XLSX)  /  Batch Konverter til PDF  /  Eksporter sider som billeder  /  Udskriv flere filer på én gang ...

Indholdsredigering: Batch Find og erstat på tværs af flere filer   /  Ændr størrelse på alle billeder   /  Transponer tabelrækker og kolonner  /  Konverter tabel til tekst ...

🧹 Ubesværet rengøringFej væk Ekstra pladser  /  Afsnit bryder  /   Alle overskrifter  /  Tekstbokse  /  Hyperlinks  /  For flere fjernelsesværktøjer, gå til vores Fjerngruppe

Kreative indlæg: indsatte Tusind adskillere  /  Afkrydsningsfelter  /  Radio knapper  /  QR kode  /  Stregkode  /  Diagonal linjebord  /  Ligningstekst  /  Billede Caption  /  Tabeltekst  /  Flere billeder  /  Opdag mere i vores Indsæt-gruppe

???? Præcisionsvalg: Find bestemte sider  /  tabeller  /  former  /  overskrifter  /  Naviger nemt ved hjælp af vores udvalgte gruppe

Stjerneforbedringer: Naviger hurtigt til ethvert sted  /  automatisk indsæt gentagende tekst  /  skifte problemfrit mellem dokumentvinduer  /  11 Konverteringsværktøjer ...

Transformer dine Word-opgaver med Kutools. 👉 Download med 30-dages prøveversion nu 🚀.

Læs mere       Gratis download      Køb
 
Comments (24)
Rated 5 out of 5 · 3 ratings
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
This comment was minimized by the moderator on the site
Reading these instructions has helped me to complete a project that would've taken 2 or more hours, in 20 minutes. Thank you so much!
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Kyle Baldwin,
It would be our pleasure to help solve your problem.
This comment was minimized by the moderator on the site
Que legal... aqui deu super certo!

Obrigada
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