Thread: [Solved] Splitting Out PDFs
View Single Post
 
Old 11-30-2012, 10:24 AM
4mysanity 4mysanity is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Nov 2012
Posts: 16
4mysanity is on a distinguished road
Default RE:

Hey there,

Thanks for the response, Ive got some good news and bad news. The script saves a PDF AND it saves the pdf with the correct text and image. The only issue is, I want to add a space between the picture and the text...For example:

Right now the text is on the same line as the image, like this:

<Image><text>

I would like it to be displayed like this:

<Image>(centered on the page)
vbNewLine
<Text About The Image Here> (aligned left)

I tried using
Code:
 Para.Range.InsertAfter vbNewLine
- but it didn't seem to do anything.

Thanks!


Here is the full code:


Code:
Sub Splitter()
Selection.EndKey Unit:=wdStory
numlets = Selection.Information(wdActiveEndSectionNumber)
If numlets > 1 Then numlets = numlets - 1
Selection.HomeKey Unit:=wdStory
BaseName = "k:\test\images"
For Counter = 1 To numlets
DocName = BaseName & Right("0" & LTrim(Str(Counter)), 10)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF
ActiveWindow.Close
Next Counter
End Sub
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

Last edited by macropod; 11-30-2012 at 04:49 PM. Reason: Deleted unnecessary quote of entire post replied to
Reply With Quote