![]() |
|
|
Thread Tools | Display Modes |
#4
|
||||
|
||||
![]()
That's what happens when you only have half the required information to work with.
![]() You will need to create a temporary document based on the original if you want the headers and footers. The path issue is addressed and the naming issue should be, thus the following will get you closer, but without access to the original document it is still based on guesswork. There should be no bookmark at the end of the original document and no manual or section page breaks in that document. If the document is the result of a mail merge use http://www.gmayor.com/MergeAndSplit.htm instead Code:
Sub Splitter2() ' 'Graham Mayor - http://www.gmayor.com - Last updated - 05 Oct 2018 ' to split a document to separate PDF files by bookmarks Dim strMask As String Dim lngDocs As Long Dim lngCount As Long Dim strName As String Dim oDoc As Document Dim oTempDoc As Document Dim oRng As Range Dim strPath As String Set oDoc = ActiveDocument oDoc.Save strPath = oDoc.path & "\" lngDocs = oDoc.Bookmarks.Count + 1 lngCount = 1 While lngCount <= lngDocs Set oRng = oDoc.Range If lngCount < lngDocs Then oRng.End = oDoc.Bookmarks(1).Range.End strMask = oDoc.Bookmarks(1).Name oDoc.Bookmarks(1).Delete End If Set oTempDoc = Documents.Add(oDoc.FullName) oTempDoc.Range.FormattedText = oRng.FormattedText strName = strMask & " " & LTrim$(Str$(lngCount)) & ".pdf" oTempDoc.ExportAsFixedFormat _ OutputFileName:=strPath & strName, _ ExportFormat:=wdExportFormatPDF, _ OptimizeFor:=wdExportOptimizeForPrint, _ CreateBookmarks:=wdExportCreateWordBookmarks, _ DocStructureTags:=True, _ BitmapMissingFonts:=True lngCount = lngCount + 1 oRng.Text = "" oTempDoc.Close wdDoNotSaveChanges Wend oDoc.Close wdDoNotSaveChanges End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
jc491 | Word VBA | 7 | 01-21-2022 11:04 AM |
![]() |
megatronixs | Word VBA | 9 | 09-05-2020 02:29 PM |
Split function in Excel (split the screen) | Officer_Bierschnitt | Excel | 1 | 07-05-2017 07:02 AM |
![]() |
Esgrimidor | Word VBA | 8 | 03-29-2017 11:15 AM |