Hi Paul,
Thank you for the changes!
I am getting a few errors when running the script, it reaches a certain point a throughs out a Run-time error '4198' Command Failed.
It is always at Document 21, could this be something to do with what the file is being saved as?
Please see below script with comments of errors.
Sub Splitter()
Application.ScreenUpdating = False
Dim i As Long, j As Long
Dim Rng As Range, StrPath As String
Dim oDoc As Document, oNewDoc As Document
Set oDoc = ActiveDocument
oDoc.Save
j = oDoc.Range.Sections.Count
'StrPath = "U:\Users\" & Environ("UserName") & "\Documents\Split\"
StrPath = "U:\My Documents\Mail merge\Split\" ' I changed the path to suit.
i = 1
For i = 1 To j
oDoc.Sections(i).Range.Copy
Set oNewDoc = Documents.Add(Template:=StrPath & "Statement Template.dotx")
With oNewDoc
With .Range
.Paste
.Characters.Last.Previous.Text = vbNullString
Set Rng = .Tables(1).Cell(Row:=2, Column:=2).Range.Paragraphs.First.Range
Rng.End = Rng.End - 1
DocName = StrPath & Rng.Text
End With
.SaveAs FileName:=DocName, FileFormat:=wdFormatPDF, AddToRecentFiles:=False -- RUN-TIME ERROR '4198' - COMMAND FAILED, only at Document 21
.Close wdDoNotSaveChanges
End With
i = i + 1
Next
oDoc.Close wdDoNotSaveChanges
Set Rng = Nothing: Set oNewDoc = Nothing: 'oDoc = Nothing -- Compile error - Invalid use or property
Application.ScreenUpdating = True
End Sub
Is it possible to have the file name set out at follows?
Client Ref - Client name, example being 1234567 - Client 1.pdf
Thanks again for all of your help!
Bookmarks