#1
|
|||
|
|||
VBA code to save to individual files and skipif function
Hi all,
I am using the following VBA code to save mailmerge records to individual files: Code:
Application.ScreenUpdating = False Dim StrFolder As String, StrName As String, MainDoc As Document, i As Long, j As Long Const StrNoChr As String = """*./\:?|" Set MainDoc = ActiveDocument With MainDoc StrFolder = .Path & Application.PathSeparator For i = 1 To .MailMerge.DataSource.RecordCount With .MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = i .LastRecord = i .ActiveRecord = i If Trim(.DataFields("Dossier")) = "" Then Exit For 'StrFolder = .DataFields("Folder") & Application.PathSeparator StrName = .DataFields("Dossier") & "_" & .DataFields("Aanvrager") End With .Execute Pause:=False End With For j = 1 To Len(StrNoChr) StrName = Replace(StrName, Mid(StrNoChr, j, 1), "_") Next StrName = Trim(StrName) With ActiveDocument .SaveAs FileName:=StrFolder & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False 'and/or: '.SaveAs FileName:=StrFolder & StrName & ".pdf", FileFormat:=wdFormatPDF, AddToRecentFiles:=False .Close savechanges:=False End With Next i End With Application.ScreenUpdating = True Thanks! Last edited by macropod; 12-04-2017 at 01:28 PM. Reason: Added code tags |
#2
|
||||
|
||||
There are numerous ways of addressing the issue. One is to use the mailmerge filters to exclude the unwanted records instead of the SKIPIF field; another is to modify the code to enclose the relevant part in an IF test that skips over the relevant records.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Thanks! Filtering is indeed an easy way to fix this
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Save mailmerge records as individual word files using VBA | beefcake2000 | Word VBA | 3 | 11-10-2017 09:55 PM |
Run Code on all files and save files as .docx | Plokimu77 | Word VBA | 4 | 06-05-2016 04:41 PM |
Mail Merge To Individual PDF Files | iamrickdeans | Mail Merge | 1 | 01-15-2014 12:46 AM |
VBA code to export individual task lists to Excel | OTPM | Excel Programming | 0 | 05-24-2011 12:23 PM |
VBA Code to Print Individual Resource Lists to a pdf File | OTPM | Project | 0 | 05-24-2011 12:21 PM |