Macro Trouble with Splitting a Mail Merge

G

Geoffrey

I have been trying to use the merge letter splitter macro from the
gmayor site to split my mail merge into individual documents, but keep
getting this error message:

"run-time error '5152':
This is not a valid file name:
Try one or more of the following:
*Check the path to make sure it was typed correctly.
*Select a file from the list of files and folders.

When I select "Debug"

This is what is shows me. The red is the highlighted portion:

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 = "D:\My Documents\Test\Merge\" & sName & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add
'Documents are based on the Normal template
'To use an alternative template follow the link.
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

I'm sorry, but I'm clueless as to macros and how to fix this. Could
anyone help?

Thanks,
 
G

Geoffrey

Sorry, the font didn't carry over.

The highlighted portion is:

ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
 

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