Mail Merge Word Code (1 Viewer)

zezo2021

Member
Local time
Today, 10:36
Joined
Mar 25, 2021
Messages
381
Hello Friends;

why this code not work
I try to merge word and save result as PDF in one Macro

Code:
Option Explicit
Public strFileName As String

Sub Make_PDF()
    With ActiveDocument.MailMerge
        .Destination = wdSendToNewDocument
        .SuppressBlankLines = True
        With .DataSource
            .FirstRecord = wdDefaultFirstRecord
            .LastRecord = wdDefaultLastRecord
        End With
        .Execute Pause:=False
    End With
    ActiveDocument.ExportAsFixedFormat OutputFileName:=strFileName, ExportFormat:= _
        wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
    ChangeFileOpenDirectory "C:\Users\Azouz\Desktop\"
End Sub
Sub ShowOpen()
strFileName = ""
Const msoFileDialogFilePicker As Long = 3

Dim FD As Object
 Set FD = Application.FileDialog(msoFileDialogSaveAs)
 
 Dim vrtSelectedItem As Variant
 

 With FD
    .AllowMultiSelect = False
    .Filters.Clear
    .Filters.Add "All Files", "*.PDF", 1
 If .Show = -1 Then
                For Each vrtSelectedItem In .SelectedItems
                    strFileName = vrtSelectedItem
                   Next vrtSelectedItem

                Else
                End If
 End With
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:36
Joined
May 7, 2009
Messages
19,169
did you Run Make_PDF sub?
 

zezo2021

Member
Local time
Today, 10:36
Joined
Mar 25, 2021
Messages
381
I find the answer
I should run file open first

but I have another Problem

how can I open file dialog save as with PDF ONLY

Application.FileDialog(msoFileDialogSaveAs) with .pdf as filter​

 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:36
Joined
May 7, 2009
Messages
19,169
The ShowOpen() sub is already doing that.
 

Users who are viewing this thread

Top Bottom