Hi,
[TD="class: votecell"]
[/TD]
[TD="class: postcell"]I am using the below Macro to split the mail merged into separate documents. What I need is it to split into separate documents keeping the whole page including the header and footers and saving as in the first merged field on the page, which is the first piece of information on the merged letters. The documents are only one page long.
However, the format is completely incorrect. It changes the font, page layout and does not include the headers and footers.
Does anyone have any idea how to amend the code below so it correctly updates with the above? I understand if this looks really bad but I am new to VBA and no one on my project to ask for help.Could someone please let me know also where to put the code for the header and footer. The code i have is below. Thanks in advance
[/TD]
[TD="class: votecell"]
[/TD]
[TD="class: postcell"]I am using the below Macro to split the mail merged into separate documents. What I need is it to split into separate documents keeping the whole page including the header and footers and saving as in the first merged field on the page, which is the first piece of information on the merged letters. The documents are only one page long.
However, the format is completely incorrect. It changes the font, page layout and does not include the headers and footers.
Does anyone have any idea how to amend the code below so it correctly updates with the above? I understand if this looks really bad but I am new to VBA and no one on my project to ask for help.Could someone please let me know also where to put the code for the header and footer. The code i have is below. Thanks in advance
[/TD]
Code:
Sub splitter()
' Based on a macro by Doug Robbins to save each letter created by a mailmerge as a separate file.
' With help from [url=http://www.productivitytalk.com/forums/topic/3927-visual-basic-question-for-merge-fields/]Visual Basic question for merge fields - SoftMed/ChartScript - Productivity Talk[/url]
Dim i As Integer
Dim Source As Document
Dim Target As Document
Dim Letter As Range
Dim oField As Field
Dim Ref As String
Set Source = ActiveDocument
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdLastRecord
For i = 1 To ActiveDocument.MailMerge.DataSource.ActiveRecord
ActiveDocument.MailMerge.DataSource.ActiveRecord = i
Set Letter = Source.Range
For Each oField In Letter.Fields
If oField.Type = wdFieldMergeField Then
If InStr(oField.Code.Text, "Ref") > 0 Then
'get the result and store it the Ref variable
Ref = oField.Result
End If
End If
Next oField
Set Target = Documents.Add
Target.Range = Letter
Target.SaveAs FileName:="[URL="file://\\svr4958file01\Libraries\u20480\Documents\On"]\\svr4958file01\Libraries\u20480\Documents\On[/URL] Hold letters Template\20150512 On hold Letters Customers Active and Cancelled\" & Ref
Target.Close
Next i
End Sub