Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-16-2020, 04:59 AM
Arwydrunk Arwydrunk is offline Choose recipient list Windows 10 Choose recipient list Office 2013
Novice
Choose recipient list
 
Join Date: Nov 2020
Posts: 1
Arwydrunk is on a distinguished road
Default Choose recipient list

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
Reply With Quote
  #2  
Old 11-16-2020, 12:38 PM
macropod's Avatar
macropod macropod is offline Choose recipient list Windows 10 Choose recipient list Office 2010
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 20,702
macropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant futuremacropod has a brilliant future
Default

Why don't you simply use the mailmerge filters to select the records to process?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Choose recipient list mailmerge not using recipient list jmcsa3 Mail Merge 5 11-07-2020 07:00 AM
Choose recipient list Sorting numerically in recipient list greengauge Mail Merge 2 05-19-2013 09:58 AM
Choose recipient list Can I have a dropdown list to choose from in mail merge? lawlaw Mail Merge 3 11-29-2012 04:47 PM
Choose recipient list 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

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 07:58 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2021 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft