Word - Merge Mail Macro para crear pdfs individuales

 
Vista:

Merge Mail Macro para crear pdfs individuales

Publicado por Paula (1 intervención) el 12/10/2017 01:15:52
Buenas tardes!

Tengo la siguiente macro que me permite crear pdfs individuales a partir del mail merge pero quisiera que cada documento se guardara en una carpeta diferente, identificada en el mail merge como MyPath, en lugar de seleccionar el destino a traves del cuadro de dialogo del inicio. Alguien podria ayudarme a actualizarla?? Muchas gracias!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
Sub merge1record_at_a_time() '
' merge1record_at_a_time Macro
'
'
    Dim fd As FileDialog
 
 
    'Create a FileDialog object as a Folder Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
 
 
        'Use the Show method to display the Folder Picker dialog box and return the user's action.
        'The user pressed the button.
        If .Show = -1 Then
                For Each vrtSelectedItem In .SelectedItems
 
 
                'vrtSelectedItem is aString that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example displays the path in a message box.
        SelectedPath = vrtSelectedItem
 
 
        Next vrtSelectedItem
 
 
        Else
        MsgBox ("No Directory Selected.  Exiting")
        Exit Sub
        End If
    End With
 
 
    'Set the object variable to Nothing.
    Set fd = Nothing
 
 
Application.ScreenUpdating = False
MainDoc = ActiveDocument.Name
    For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
        SelectedPath = .DataFields("MyPath").Value
        ChangeFileOpenDirectory SelectedPath
        With ActiveDocument.MailMerge
            .Destination = wdSendToNewDocument
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = i
                .LastRecord = i
                .ActiveRecord = i
                docName = .DataFields("Sigla").Value & "_" & .DataFields("Last_Name").Value & " " & .DataFields("First_Name").Value & ".pdf"
            End With
            .Execute Pause:=False
    Application.ScreenUpdating = False
 
        End With
 
   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
 
'set OpenAfterExport to False so the PDF files won't open after mail merge
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
 
    Windows(MainDoc).Activate
    Next i
Application.ScreenUpdating = True
 
 
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder