Thread: [Solved] Splitting Out PDFs
View Single Post
 
Old 11-29-2012, 04:18 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,370
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

From what you've described, the code to insert the images would be something like:
Code:
Sub InsertPicsToPDF()
Application.ScreenUpdating = False
Dim Para As Paragraph, Str As String, i As Long, Rng As Range
With ActiveDocument
  For Each Para In .Paragraphs
    Str = Trim(Para.Range.Words.First)
    If Str Like "###" Then
      Para.Range.InsertBefore Chr(12)
      Para.Range.InsertAfter vbCr
      .InlineShapes.AddPicture FileName:="K:\test\images\" & Str & ".jpg", _
        LinkToFile:=False, SaveWithDocument:=True, Range:=Para.Range.Characters.Last
    End If
  Next
  .Characters.First.Delete
  For i = 1 To .ComputeStatistics(wdStatisticPages)
    Set Rng = ActiveDocument.GoTo(What:=wdGoToPage, Name:=i)
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    If Rng.Characters.Last = Chr(12) Then Rng.MoveEnd wdCharacter, -1
    Str = Trim(Rng.Words.First)
    Rng.Copy
    Documents.Add
    With ActiveDocument
      .Range.Paste
      .SaveAs2 FileName:="K:\test\images\" & Str & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False
      .Close SaveChanges:=False
    End With
  Next
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
To generate the PDFs you would need to have each record on its own page, which the macro does.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote