Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2013, 11:29 AM
amlong amlong is offline Save as PDF - How to add extra functionality to split by page break Windows XP Save as PDF - How to add extra functionality to split by page break Office 2007
Novice
Save as PDF - How to add extra functionality to split by page break
 
Join Date: Feb 2013
Posts: 5
amlong is on a distinguished road
Default Save as PDF - How to add extra functionality to split by page break


The code you posted at https://www.msofficeforums.com/word-...html#post18401 works perfectly, but can it be enhanced to split the word mail merge by page break and save each individual file to pdf?

Any assistance you could give would be appreciated.

Thanks
A
Code:
Sub SaveToPDF()
Dim StrPath As String, StrName As String, Result
With ActiveDocument
  On Error GoTo Errhandler
  StrPath = GetFolder & "\"
  StrName = Split(.Name, ".")(0)
  While Dir(StrPath & StrName & ".pdf") <> ""
    Result = InputBox("WARNING - A file already exists with the name:" & vbCr & _
      Split(.Name, ".")(0) & vbCr & _
      "You may edit the filename or continue without editing." _
      & vbCr & vbTab & vbTab & vbTab & "Proceed?", "File Exists", StrName)
    If Result = vbCancel Then Exit Sub
    If StrName = Result Then GoTo Overwrite
    StrName = Result
  Wend
Overwrite:
  .ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
  OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
  Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
  CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
  BitmapMissingFonts:=True, UseISO19005_1:=False
End With
Errhandler:
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

Last edited by macropod; 02-22-2013 at 08:41 PM. Reason: Split to new thread, with links & code
Reply With Quote
  #2  
Old 02-22-2013, 08:43 PM
macropod's Avatar
macropod macropod is offline Save as PDF - How to add extra functionality to split by page break Windows 7 64bit Save as PDF - How to add extra functionality to split by page break Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Yes, that's possible, but it would require a fair bit of re-working and how would each PDF be named?

PS: I moved your initial post to a new thread.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 02-22-2013, 09:19 PM
amlong amlong is offline Save as PDF - How to add extra functionality to split by page break Windows XP Save as PDF - How to add extra functionality to split by page break Office 2007
Novice
Save as PDF - How to add extra functionality to split by page break
 
Join Date: Feb 2013
Posts: 5
amlong is on a distinguished road
Default

Hi Paul

The first line of each merge (after the header data) has the naming convention for the letters that comprise of a few merge fields put together + .pdf. The first lines will look something like this:

2619.T138.09.20.12.pdf
2619.MHRPD.09.20.12.pdf


2619.9110.09.20.12.pdf


I will prepare a washed sample file and attach.

Thanks
Andrea
Reply With Quote
  #4  
Old 02-22-2013, 09:38 PM
amlong amlong is offline Save as PDF - How to add extra functionality to split by page break Windows XP Save as PDF - How to add extra functionality to split by page break Office 2007
Novice
Save as PDF - How to add extra functionality to split by page break
 
Join Date: Feb 2013
Posts: 5
amlong is on a distinguished road
Default

Hi

Here is a sample of the mail merge document.

Thanks
Andrea
Attached Files
File Type: docx Sample merge.docx (74.7 KB, 9 views)
Reply With Quote
  #5  
Old 02-22-2013, 10:16 PM
macropod's Avatar
macropod macropod is offline Save as PDF - How to add extra functionality to split by page break Windows 7 64bit Save as PDF - How to add extra functionality to split by page break Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Andrea,

Since you're proposing to use this with mailmerge, I suggest you take a look at: http://www.gmayor.com/individual_merge_letters.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 02-22-2013, 10:20 PM
amlong amlong is offline Save as PDF - How to add extra functionality to split by page break Windows XP Save as PDF - How to add extra functionality to split by page break Office 2007
Novice
Save as PDF - How to add extra functionality to split by page break
 
Join Date: Feb 2013
Posts: 5
amlong is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hi Andrea,

Since you're proposing to use this with mailmerge, I suggest you take a look at: http://www.gmayor.com/individual_merge_letters.htm
Unfortunately, the company i work for will not allow the addin
Reply With Quote
  #7  
Old 02-22-2013, 11:29 PM
macropod's Avatar
macropod macropod is offline Save as PDF - How to add extra functionality to split by page break Windows 7 64bit Save as PDF - How to add extra functionality to split by page break Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Andrea,

Try:
Code:
Sub ExportPagesToPDF()
Dim StrPath As String, StrName As String, Rng As Range
StrPath = GetFolder & "\"
With ActiveDocument
  Set Rng = .Range(0, 0)
  With .Range
    With .Characters.Last
      While .Previous Like "[" & Chr(9) & "-" & Chr(14) & Chr(32) & Chr(160) & "]"
        .Previous.Text = vbNullString
      Wend
    End With
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = Chr(12)
      .Replacement.Text = ""
      .Forward = True
      .Wrap = wdFindStop
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Execute
    End With
    Do While .Find.Found
      Rng.End = .End
      StrName = Split(Split(Rng.Text, vbCr)(0), " ")(0)
      With Rng.Characters
        Call SavePDF(ActiveDocument, StrPath, StrName, .First.Information(wdActiveEndPageNumber), .Last.Information(wdActiveEndPageNumber))
      End With
      Rng.Collapse wdCollapseEnd
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
  Rng.End = .Range.End
  StrName = Split(Split(Rng.Text, vbCr)(0), " ")(0)
  With Rng.Characters
    Call SavePDF(ActiveDocument, StrPath, StrName, .First.Information(wdActiveEndPageNumber), .Last.Information(wdActiveEndPageNumber))
  End With
End With
End Sub
 
Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function
 
Sub SavePDF(Doc As Document, StrPath As String, StrName As String, StartPage As Long, EndPage As Long)
Dim Result As String
On Error GoTo Errhandler
While Dir(StrPath & StrName) <> ""
  Result = InputBox("WARNING - A file already exists with the name:" & vbCr & _
    StrName & vbCr & _
    "You may edit the filename or continue without editing." _
    & vbCr & vbTab & vbTab & vbTab & "Proceed?", "File Exists", StrName)
  If Result = "" Then Exit Sub
  If StrName = Result Then GoTo Overwrite
  StrName = Result
Wend
Overwrite:
Doc.ExportAsFixedFormat OutputFileName:=StrPath & StrName, UseISO19005_1:=False, _
  ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
  OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportFromTo, _
  From:=StartPage, To:=EndPage, Item:=wdExportDocumentContent, _
  IncludeDocProps:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
  KeepIRM:=True, DocStructureTags:=True, BitmapMissingFonts:=True
  Exit Sub
Errhandler:
  MsgBox "Error processing: " & StrName, vbExclamation
End Sub
So far as the code is concerned, it doesn't matter whether manual page breaks or Section breaks are used to delineate the reports; just don't use, say, continuous Section breaks within a report or it will get split.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 02-22-2013, 11:34 PM
amlong amlong is offline Save as PDF - How to add extra functionality to split by page break Windows XP Save as PDF - How to add extra functionality to split by page break Office 2007
Novice
Save as PDF - How to add extra functionality to split by page break
 
Join Date: Feb 2013
Posts: 5
amlong is on a distinguished road
Default

Paul

I have never seen a more beautiful thing in all my life.

<3


you should add this to that mail merge tutorial doc. it is very useful.

Andrea
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Save as PDF - How to add extra functionality to split by page break Delete a page after Section Break Next Page Aston Word 9 04-27-2022 07:38 AM
Page break? Jon Word 3 01-29-2013 09:08 AM
Save as PDF - How to add extra functionality to split by page break Word extra spacing on page break ellinj Word 4 03-21-2011 05:12 PM
paragaph hard break, soft break and ...strange break czomberzdaniela Word 2 12-03-2010 06:58 PM
Page Break Manolo Word 0 04-29-2009 11:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft