R
richard_stockley
Hi,
I have a macro which splits a mailmerged document into its constituant
letters. I want this macro to name each file according to a specific
name so I have created a variable Yipname. I cant understand why i get
a subscript out of range error with the following code. I'm pretty new
to VBA so sorry if I'm missing something fairly obvious. You can assume
that there are only 10 letters in the mail merge document.
Sub Splitter()
' splitter Macro
' saves each letter created by a mailmerge as a separate file.
Dim Yipname() As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Yipname(1) = "Barking and Dagenham"
Yipname(2) = "Barrow-in-Furness "
Yipname(3) = "Birmingham Kingstanding"
Yipname(4) = "Birmingham Shard End"
Yipname(5) = "Birmingham Washwood Heath"
Yipname(6) = "Blackburn Mill Hill"
Yipname(7) = "Bolton"
Yipname(8) = "Bournemouth"
Yipname(9) = "Bradford NDC"
Yipname(10) = "Bradford Newlands"
Selection.HomeKey Unit:=wdStory
counter = 1
While counter < Letters
DocName = "c:\feedback\" & Yipname(counter)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
counter = counter + 1
Wend
End Sub
many thanks for any help.
I have a macro which splits a mailmerged document into its constituant
letters. I want this macro to name each file according to a specific
name so I have created a variable Yipname. I cant understand why i get
a subscript out of range error with the following code. I'm pretty new
to VBA so sorry if I'm missing something fairly obvious. You can assume
that there are only 10 letters in the mail merge document.
Sub Splitter()
' splitter Macro
' saves each letter created by a mailmerge as a separate file.
Dim Yipname() As String
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Yipname(1) = "Barking and Dagenham"
Yipname(2) = "Barrow-in-Furness "
Yipname(3) = "Birmingham Kingstanding"
Yipname(4) = "Birmingham Shard End"
Yipname(5) = "Birmingham Washwood Heath"
Yipname(6) = "Blackburn Mill Hill"
Yipname(7) = "Bolton"
Yipname(8) = "Bournemouth"
Yipname(9) = "Bradford NDC"
Yipname(10) = "Bradford Newlands"
Selection.HomeKey Unit:=wdStory
counter = 1
While counter < Letters
DocName = "c:\feedback\" & Yipname(counter)
ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
counter = counter + 1
Wend
End Sub
many thanks for any help.