Ir para o conteúdo principal

Como salvar cada página como arquivos PDF separados em um documento do Word?

Ao usar o documento do Microsoft Word, você pode salvar cada página como arquivos PDF separados, um por um, com a função Salvar como embutida. No entanto, se houver centenas de páginas que precisam ser divididas e salvas como arquivos PDF individuais, como você pode fazer? Este artigo fornece um método para você resolver rapidamente esse problema.

Salve cada página como arquivos PDF separados em massa com o código VBA


Salve cada página como arquivos PDF separados em massa com o código VBA

O código VBA abaixo ajuda você a salvar rapidamente cada página de um documento como arquivos PDF individuais ao mesmo tempo. Faça o seguinte.

1. Abra o documento em que você salvará cada página ou páginas específicas como arquivos PDF e pressione o botão outro + F11 chaves para abrir o Microsoft Visual Basic para Aplicações janela.

2. No Microsoft Visual Basic para Aplicações janela, clique em inserção > Módulo, copie o código VBA abaixo na janela do módulo.

Código VBA: salve cada página como arquivos PDF separados ao mesmo tempo em um documento do 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. aperte o F5 chave para executar o código.

4. No Procurar janela, selecione uma pasta para salvar os arquivos PDF e clique no OK botão. Veja a imagem:

5. No primeiro Kutools for Word caixa de diálogo, digite o número da página inicial do seu documento na caixa de texto e clique OK.

6. Na segunda Kutools for Word caixa de diálogo, digite o número da última página do seu documento e clique em OK. Veja a imagem:

Note: Se você deseja apenas salvar várias páginas continuamente no documento como arquivos PDF separados, como as páginas 4, 5 e 6, digite 4 e 6 separadamente nas duas caixas de diálogo acima.

Depois de executar o código, vá para a pasta especificada que você selecionou na etapa 4, você pode ver que todas as páginas são divididas e salvas como arquivos PDF individuais conforme a captura de tela mostrada abaixo.


Divida e salve cada página de um documento como novos documentos separados:

A Dividir Documento utilidade de Kutools for Excel pode ajudá-lo a dividir e salvar facilmente cada página do documento atual como um novo documento separado em massa, conforme mostrado na captura de tela abaixo. Baixe e experimente agora! (60-dia de trilha livre)

Melhores ferramentas de produtividade de escritório

Kutools for Word - Eleve sua experiência com palavras com mais 100 Recursos notáveis!

🤖 Assistente de IA do Kutools: Transforme sua escrita com IA - Gerar conteúdo  /  Reescrever texto  /  Resumir documentos  /  Pergunte para obter informações com base no documento, tudo dentro do Word

📘 Domínio de documentos: Páginas divididas  /  Mesclar Documentos  /  Seleção de exportação em vários formatos (PDF/TXT/DOC/HTML...)  /  Conversão em lote para PDF  /  Exportar páginas como imagens  /  Imprima vários arquivos de uma vez...

Edição de conteúdo: Localização e substituição em lote em vários arquivos  /  Redimensionar todas as imagens  /  Transpor linhas e colunas da tabela  /  Converter tabela em texto...

🧹 Limpeza sem esforço: Varrer Espaços extras  /  Quebras de seção  /  Todos os cabeçalhos  /  Caixas de Texto  /  hiperlinks  / Para mais ferramentas de remoção, acesse nosso Remover Grupo...

Inserções criativas: Inserir Mil Separadores  /  Caixas de seleção  /  botões de rádio  /  QR Code  /  Código de barras  /  Tabela de linhas diagonais  /  Legenda da equação  /  Legenda da Imagem  /  Legenda da Tabela  /  Várias fotos  / Descubra mais no Inserir Grupo...

🔍 Seleções de precisão: Identificar páginas específicas  /  tabelas  /  formas  /  parágrafos de título  / Melhore a navegação com mais Selecione recursos...

Aprimoramentos de estrelas: Navegue rapidamente para qualquer local  /  inserir automaticamente texto repetitivo  /  alternar perfeitamente entre janelas de documentos  /  11 ferramentas de conversão...

👉 Quer experimentar esses recursos? Kutools para Word oferece um 60-day free trial, sem limitações! 🚀
 
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