![]() |
|
#1
|
|||
|
|||
|
Hi, I am working in a mail merge document and I'm trying to create a macro that allows to select the recipient list, currently I have to type the path, this is my code: Code:
Sub Autocombineta()
Dim URL As String
URL = InputBox("¿Donde desea crear los documentos? agregar \ al final de la ruta")
Dim SOURCE_FILE_PATH As String
SOURCE_FILE_PATH = InputBox("¿Elija la lista de destinatarios")
Dim MainDoc As Document, TargetDoc As Document
Dim dbPath As String
Dim recordNumber As Long, totalRecord As Long
Set MainDoc = ActiveDocument
With MainDoc.MailMerge
'Indicar entre paréntesis la solapa de excel que contiene los datos, poner el signo $ al final'
.OpenDataSource Name:=SOURCE_FILE_PATH, SQLStatement:="SELECT * FROM [Prueba$]"
totalRecord = .DataSource.RecordCount
For recordNumber = 1 To totalRecord
With .DataSource
.ActiveRecord = recordNumber
.FirstRecord = recordNumber
.LastRecord = recordNumber
End With
.Destination = wdSendToNewDocument
.Execute False
Set TargetDoc = ActiveDocument
TargetDoc.ExportAsFixedFormat URL & .DataSource.DataFields("Encabezado").Value & ".pdf", exportformat:=wdExportFormatPDF
TargetDoc.Close False
Set TargetDoc = Nothing
Next recordNumber
End With
Set MainDoc = Nothing
End Sub
Last edited by macropod; 11-16-2020 at 12:37 PM. Reason: Added code tags |
|
#2
|
||||
|
||||
|
Why don't you simply use the mailmerge filters to select the records to process?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
mailmerge not using recipient list
|
jmcsa3 | Mail Merge | 5 | 11-07-2020 07:00 AM |
Sorting numerically in recipient list
|
greengauge | Mail Merge | 2 | 05-19-2013 09:58 AM |
Can I have a dropdown list to choose from in mail merge?
|
lawlaw | Mail Merge | 3 | 11-29-2012 04:47 PM |
How to edit recipient list
|
rsmedley | Mail Merge | 1 | 03-17-2012 01:35 AM |
| Problem with Edit Recipient List | TanMan | Word | 0 | 10-05-2011 12:34 PM |