Runtime error 5690

C

Carrie L.

I'm using the code below to create separate word documents from a mail merge.
I have 30 different letters and will generate about 5000 documents. I've
done about half, but on a couple of the mail merges I am getting the error
above and can't figure out why it is only happening on some of the letters.
I am setting them up myself and basically using the same merge fields - the
first being the document name. HELP!


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:\Test\" & 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
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With

'here go to end, backspace, backspace, delete

Selection.EndKey Unit:=wdStory
Selection.TypeBackspace
Selection.TypeBackspace
Selection.Delete Unit:=wdCharacter, Count:=1
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub
 
C

Carrie L.

Just wanted to add that the error occurs when it tries to execute the

ActiveDocument.Sections.First.Range.Cut

It says that the "selection is marked as deleted text."

It does the first letter in the merge file, but stops on the second letter.
I've tried deleting the second letter, but the problem persists and I can't
understand what it thinks is missing.
 

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