Hi All,
We have some old code that we use to basically create a mail merge from a data set as individual letters.
I didn't write the code but i need to find away to password protect the each file with a specific password for example say Field1&Field2. Could anyone help with this?
Thanks in advance
We have some old code that we use to basically create a mail merge from a data set as individual letters.
I didn't write the code but i need to find away to password protect the each file with a specific password for example say Field1&Field2. Could anyone help with this?
Code:
Sub lettermaker()
Application.ScreenUpdating = False
Dim StrPath As String, StrName As String, MainDoc As Document
Application.ScreenUpdating = False
Set MainDoc = ActiveDocument
With MainDoc
For i = 1 To .MailMerge.DataSource.RecordCount
With .MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
StrName = .DataFields("LetterName")
StrPath = "C:\Users\Craig.Crosby\Desktop\Letters\2017\" & .DataFields("Folder")\" & .DataFields("BP")& "\"
If Len(Dir(StrPath, vbDirectory)) = 0 Then
MkDir StrPath
End If
End With
.Execute Pause:=False
End With
With ActiveDocument
'.SaveAs2 FileName:=StrPath & StrName & ".docx", FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
'.SaveAs FileName:=StrPath & StrName & ".doc", FileFormat:=wdFormatDocument, AddToRecentFiles:=False
.ExportAsFixedFormat OutputFileName:=StrPath & StrName & ".pdf", ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
Item:=wdExportDocumentContent, IncludeDocProps:=True, CreateBookmarks:=wdExportCreateNoBookmarks, _
KeepIRM:=True, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
.Close SaveChanges:=False
End With
Next i
End With
Application.ScreenUpdating = False
End Sub
Thanks in advance