S
shaz23
I've done a mail merge in Word 2002 and am trying to save each letter as its
own file with its own name.
I came across this script which seemed to address what I needed to do (see
http://www.gmayor.com/individual_merge_letters.htm) :
------------------------------------
Sub SplitMergeLetter()
' splitter Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter - see web article.
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
DocName = "C:\Temp\" & sName
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub
------------------------------------
Unfortunately, when I run the Macro, I get the following error:
Run-time error '5487'
Word cannot complete the save due to a file permission error.
There were two other sample scripts on this page:
http://www.gmayor.com/individual_merge_letters.htm which were similar in
nature, and which didn't give me the same error when I ran the macro.
I'm not a programmer, so I was wondering if there's a bug in the script here
that anyone can spot.
Thanks.
own file with its own name.
I came across this script which seemed to address what I needed to do (see
http://www.gmayor.com/individual_merge_letters.htm) :
------------------------------------
Sub SplitMergeLetter()
' splitter Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter - see web article.
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
DocName = "C:\Temp\" & sName
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=DocName, FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub
------------------------------------
Unfortunately, when I run the Macro, I get the following error:
Run-time error '5487'
Word cannot complete the save due to a file permission error.
There were two other sample scripts on this page:
http://www.gmayor.com/individual_merge_letters.htm which were similar in
nature, and which didn't give me the same error when I ran the macro.
I'm not a programmer, so I was wondering if there's a bug in the script here
that anyone can spot.
Thanks.