メインコンテンツへスキップ

Word文書を5ページまたはnページごとに別々のファイルに分割するにはどうすればよいですか?

数百ページを含む大きなWord文書があり、今、この文書を10ページまたはnページごとに別々のファイルに分割したいとします。 ページをXNUMXつずつコピーして貼り付けることなく、このジョブをすばやく簡単に解決する方法はありますか?

Word文書をVBAコードで10ページまたはnページごとに別々のファイルに分割する

驚くべき機能を備えたWord文書を10ページまたはnページごとに別々のファイルに分割する


Word文書をVBAコードで10ページまたはnページごとに別々のファイルに分割する

大きなドキュメントを10ページまたはnページごとに別々のファイルに分割するには、次のVBAコードを使用すると便利です。次のようにしてください。

1。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

2。 次に、をクリックします インセット > モジュール、以下のコードをコピーして、開いた空白のモジュールに貼り付けます。

VBAコード:ドキュメントを10ページまたはnページごとに個別のファイルに分割します。

Sub DocumentSplitter()
    Dim xDoc As Document, xNewDoc As Document
    Dim xSplit As String, xCount As Long, xLast As Long
    Dim xRngSplit As Range, xDocName As String, xFileExt As String
    Dim xRegEx As RegExp
    Dim xPageCount As Integer
    Dim xShell As Object, xFolder As Object, xFolderItem As Object
    Dim xFilePath As String
    On Error Resume Next
    Set xDoc = Application.ActiveDocument
    Set xShell = CreateObject("Shell.Application")
    Set xFolder = xShell.BrowseforFolder(0, "Select a Folder:", 0, 0)
    If TypeName(xFolder) = "Nothing" Then Exit Sub
    Set xFolderItem = xFolder.Self
    xFilePath = xFolderItem.Path & "\"
    Application.ScreenUpdating = False
    Set xNewDoc = Documents.Add(Visible:=False)
    xDoc.Content.WholeStory
    xDoc.Content.Copy
    xNewDoc.Content.PasteAndFormat wdFormatOriginalFormatting
    With xNewDoc
        xPageCount = .ActiveWindow.Panes(1).Pages.Count
L1:     xSplit = InputBox("The document contains " & xPageCount & " pages." & _
                 vbCrLf & vbCrLf & " Please enter the page count you want to split:", "Kutools for Word", xSplit)
        If Len(Trim(xSplit)) = 0 Then Exit Sub
        Set xRegEx = New RegExp
        With xRegEx
            .MultiLine = False
            .Global = True
            .IgnoreCase = True
            .Pattern = "[^0-9]"
        End With
        If xRegEx.Test(xSplit) = True Then
            MsgBox "Please enter the page number:", vbInformation, "Kutools for Word"
            Exit Sub
        End If
        If VBA.Int(xSplit) >= xPageCount Then
            MsgBox "The number is greater than the document number." & vbCrLf & "Please re-enter", vbInformation, "Kutools for Word"
            GoTo L1
        End If
        xDocName = xDoc. Name
        xFileExt = VBA.Right(xDocName, Len(xDocName) - InStrRev(xDocName, ".") + 1)
        xDocName = Left(xDocName, InStrRev(xDocName, ".") - 1) & "_"
        xFilePath = xFilePath & xDocName
        For xCount = 0 To Int(xPageCount / xSplit)
            xPageCount = .ActiveWindow.Panes(1).Pages.Count
            If xPageCount > xSplit Then
                xLast = xSplit
            Else
                xLast = xPageCount
            End If
            Set xRngSplit = .GoTo(What:=wdGoToPage, Name:=xLast)
            Set xRngSplit = xRngSplit.GoTo(What:=wdGoToBookmark, Name:="\page")
            xRngSplit.Start = .Range.Start
            xRngSplit.Cut
            Documents.Add
            Selection.Paste
            ActiveDocument.SaveAs FileName:=xFilePath & xCount + 1 & xFileExt, AddToRecentFiles:=False
            ActiveWindow.Close
        Next xCount
        Set xRngSplit = Nothing
        xNewDoc.Close wdDoNotSaveChanges
        Set xNewDoc = Nothing
    End With
    Application.ScreenUpdating = True
End Sub

3。 上記のコードを貼り付けた後、まだ アプリケーション向け Microsoft Visual Basic ウィンドウをクリックしてください ツール > 参考文献、そして飛び出した 参考資料-プロジェクト ダイアログボックス、チェック MicrosoftVBScript正規表現5.5 内のオプション 利用可能な参考文献 リストボックス、スクリーンショットを参照:

4。 次に、をクリックします OK ボタンをクリックし、を押します F5 このコードを実行するためのキー、および フォルダを参照 ダイアログボックスが表示されます。分割ファイルを配置するフォルダを選択してください。スクリーンショットを参照してください。

5。 次に、をクリックします OK ボタンをクリックすると、別のプロンプトボックスが表示され、分割するページ数を入力するように促されます。スクリーンショットを参照してください。

6。 そして、 OK ボタンをクリックすると、アクティブなWord文書が10ページごとに個別のファイルに分割され、指定したフォルダーに移動して結果を確認できます。


驚くべき機能を備えたWord文書を10ページまたはnページごとに別々のファイルに分割する

Kutools for Word 強力な機能が含まれています- スプリット このユーティリティを使用すると、大きなWord文書を、見出し1、改ページ、セクション区切り、およびページに基づいて、複数の個別のファイルにすばやく分割できます。

ヒント:これを適用する スプリット 機能、まず、ダウンロードする必要があります Kutools for Word、次に機能をすばやく簡単に適用します。

インストールした後 Kutools for Word、次のようにしてください。

1に設定します。 OK をクリックします。 クツールズプラス > スプリット、スクリーンショットを参照してください:

2。 ポップアウトされたダイアログボックスで、必要に応じて次の操作を設定してください。スクリーンショットを参照してください。

3。 設定終了後、をクリックしてください OK、およびドキュメント全体が各ページに基づいて複数のファイルに分割されます。スクリーンショットを参照してください。

クリックしてKutoolsfor Wordと無料トライアルを今すぐダウンロードしてください!

最高のオフィス生産性向上ツール

Kutools for Word - Over で単語体験を向上させましょう 100 注目すべき機能!

🤖 Kutools AI アシスタント: AI であなたの文章を変革します - コンテンツを生成する  /  テキストを書き換える  /  文書を要約する  /  情報のお問い合わせ 文書に基づいて、すべて Word 内で

📘 ドキュメントマスタリー: 分割ページ  /  ドキュメントをマージする  /  選択内容をさまざまな形式でエクスポート (PDF/TXT/DOC/HTML...)  /  PDFへの一括変換  /  ページを画像としてエクスポート  /  複数のファイルを一度に印刷する...

コンテンツ編集: バッチ検索と置換 複数のファイルにわたる  /  すべての画像のサイズを変更する  /  テーブルの行と列を転置する  /  表をテキストに変換...

🧹 楽にお掃除:振り払って 余分なスペース  /  セクションブレーク  /  すべてのヘッダー  /  テキストボックス  /  ハイパーリンク  / その​​他の取り外しツールについては、当社の Web サイトをご覧ください。 グループを削除...

クリエイティブインサート:挿入 千の区切り文字  /  チェックボックス  /  ラジオボタン  /  QRコード  /  バーコード  /  斜線テーブル  /  方程式のキャプション  /  画像キャプション  /  テーブルキャプション  /  複数の写真  / 詳細については、 グループを挿入...

🔍 正確な選択: ピンポイント 特定のページ  /  テーブル  /  シェイプ  /  見出し段落  / ナビゲーションを強化する 他には? 機能の選択...

スターの強化: あらゆる場所に素早く移動  /  繰り返しのテキストを自動挿入  /  ドキュメントウィンドウをシームレスに切り替える  /  11 変換ツール...

👉 これらの機能を試してみませんか? Kutools for Wordは、 60日無料トライアル、制限なし! 🚀
 
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
good things. i used it to split with 1 page 1 word document, it was successful except that each document (after split), it has 2 pages in total although 2nd page is always blank. 
This comment was minimized by the moderator on the site
this code gives compile error which shows user define type is not define
This comment was minimized by the moderator on the site
For me, the VBA creates a single document that is a copy of the original and that's it.
This comment was minimized by the moderator on the site
The VBscript code made Word crash. I was trying to split a 32Mb Word file with many pages but it seems Word can't handle it through VBscript.
Thanks anyway
This comment was minimized by the moderator on the site
Hello, Studia,
The VBA code may crash when there is a large document, it is not stable, so I recommend you use our Kutools for Word tool, it has updated, and support to solve this task, you can download it and free trial 30 day.
Please try, thank you!
This comment was minimized by the moderator on the site
VBA Script: Split a document into separate files every 10 or n pages not worked
This comment was minimized by the moderator on the site
Hello, Sergey,
The above code works well in my Word document, which Word version do you use?
And which step went wrong in your operation?
This comment was minimized by the moderator on the site
i have been trying to split a word file of 166 pages and it gives 166 files each with 166 pages?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations