Mail Merge -- Saving the Document

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.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?c2hhejIz?=,

You should ask this in the mail merge support group. That's where you'll find
Graham Mayor, whose code this is.
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.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top