PDA

View Full Version : MS Word crashing when running "individual documents staple" during mail merge macro



MaggiePAH
09-10-2017, 10:51 PM
Dear Forum Posters,
I was hoping to get your help. I need to use mail merge in Word 2010 but need it to staple each document independently, not all together. I found a macro that half worked on the first go (printed 67 out of 120 documents, stapled individually) and then froze my Word document. Subsequently every time I try to use it, it crashes almost immediately. I tried finding answers and there was something similar already here but I did not understand the solution - something about deleting some file in the 'library' (I'm a pretty basic Word user). I am on a network drive at work and do not have access to hidden or system files.

The macro I used is as follows:
Sub SeparateStapleMailMerg()
Application.ScreenUpdating = False
Dim i As Long
With ActiveDocument
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
.Execute Pause:=False
End With
Next i
End With
Application.ScreenUpdating = True
End Sub

Any help would be greatly appreciated!

gmayor
09-10-2017, 11:31 PM
The macro could benefit from a couple of lines of additional help (see below) to ensure it processes without interruption. Crashes suggest that you may have orphaned temporary files relating to the documents and templates open at the time of the crash and thyese will need to be cleared. They are hidden files so you need to display hidden files using the options in Windows File Explorer in order to do so (or get your IT support to do so) - see http://www.gmayor.com/what_to_do_when_word_crashes.htm (http://www.gmayor.com/what_to_do_when_word_crashes.htm)

Reboot the PC before trying again to clear any stored error conditions in Office.

If your data is in Excel and all else fails - see http://www.gmayor.com/ManyToOne.htm . In One to One mode, a merge to the printer will emulate a merge to individual documents but without using mail merge.


Sub SeparateStapleMailMerg()
Dim i As Long
Dim bBack As Boolean
Application.ScreenUpdating = False
bBack = Options.PrintBackground 'add this line
Options.PrintBackground = False
With ActiveDocument
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
End With
.Execute Pause:=False
End With
DoEvents 'add this line
Next i
End With
Options.PrintBackground = bBack 'add this line
Application.ScreenUpdating = True
End Sub

MaggiePAH
09-17-2017, 11:37 PM
Thank you so much for your reply. I will get IT to clear the files and see what happens. I attempted to do it myself but wasn't able to locate all the folders.
:-)