![]() |
|
#1
|
||||
|
||||
|
Hello
I use a macro to save mail merged documents into word and PDF files; very handy. I must select all the rows above the row I need in the recipient list for it to work. If I only ticked "Sam" and left "Connor" and "Vincent" unticked, the macro will produce a "runtime error 5631" on Code:
.Execute Pause:=False This is unmanageable with 1000's of rows. The macro takes ages to run and I then have to delete all the documents I don't need after. MS Forum Pic.png Is it possible to fix the below so it will run on any row/rows I have selected in the recipient list, regardless of if the leading rows are selected? Code:
Sub Split_2_PDF()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
SelectedPath = vrtSelectedItem
Next vrtSelectedItem
Else
MsgBox ("No Directory Selected. Exiting")
Exit Sub
End If
End With
Set fd = Nothing
Application.ScreenUpdating = False
MainDoc = ActiveDocument.Name
ChangeFileOpenDirectory SelectedPath
For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
docname = .DataFields("File_Name")
End With
.Execute Pause:=False
Application.ScreenUpdating = False
End With
'export pdf
ActiveDocument.ExportAsFixedFormat OutputFileName:=docname, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveDocument.Saved = True
'export word
ActiveDocument.SaveAs2 FileName:=docname & ".docx"
ActiveDocument.Saved = True
ActiveDocument.ActiveWindow.Close savechanges:=wdDoNotSaveChanges
Documents(MainDoc).Activate
Next i
Application.ScreenUpdating = True
End Sub
|
|
#2
|
||||
|
||||
|
Anyone able to help?
|
|
#3
|
||||
|
||||
|
This question looks similar to this one.
https://www.msofficeforums.com/word-...e-records.html Does that help you work out how to iterate across the records to work only with the selected ones?
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
| Tags |
| macro, mail merge, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Excel Macro buttons to run PDF mail merge for a singular data entry with preset Word document | JA6 | Excel Programming | 0 | 04-10-2024 07:32 AM |
Creating a macro from a non-saved Word doc that duplicates the current open document and saves it
|
mike0215 | Word VBA | 3 | 11-17-2017 01:40 PM |
Mail Merge Macro
|
ch1325 | Word VBA | 2 | 06-08-2015 06:18 AM |
| Mail Merge Macro | spc94 | Word VBA | 2 | 06-04-2015 07:06 AM |
Word Doc Macro (mail Merge)
|
ajolson1964 | Word VBA | 1 | 05-10-2011 10:15 PM |