Hello everyone,
I'm currently trying to piece together a Word macro to achieve the following.
I have an Excel spreadsheet that contains my merge data and a Word document which is a single page form that the data merges into.
Step by step, record by record I would like to:
1. Merge a record into the form
2. Password protect the entire document to prevent editing
3. Allow certain areas of the document to be edited by using pre-defined bookmarks on the document
4. Email the form as an attachment using an email address from the current record but be able to add some pre-defined text into the body of the email
5. Save the form into a folder
6. Loop the above until all records have been merged, protected, emailed and saved
So far I have a macro that does everything perfectly aside from step 4, I'd be grateful if anyone could assist me with adding the email attachment process defined in step 4 :
Sub ProtectSaveEmail()
'
' MergeProtectEmailSave Macro
'
'
Dim i As Long
i = ActiveDocument.MailMerge.DataSource.RecordCount
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdFirstRecord
Do While intCounter < i
intCounter = intCounter + 1
' Copy the active record
ActiveDocument.Range.Copy
' Create a new document and paste the record
Documents.Add
Selection.Paste
' Set the open directory where the file is to be saved
ChangeFileOpenDirectory _
"D:\Merged Forms"
' Remove the mail merge from the document
ActiveDocument.MailMerge.MainDocumentType = wdNotAMergeDocument
' Select all and replace all fields with their text values
Selection.WholeStory
Selection.Fields.Unlink
' Restrict editing of the document
ActiveDocument.Protect Password:="a-password-goes-here", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
' Allow editing of 6 fields in the document by using pre-defined bookmarks
ActiveDocument.Bookmarks("EDIT1").Select
Selection.Range.Editors.Add wdEditorEveryone
ActiveDocument.Bookmarks("EDIT2").Select
Selection.Range.Editors.Add wdEditorEveryone
ActiveDocument.Bookmarks("EDIT3").Select
Selection.Range.Editors.Add wdEditorEveryone
ActiveDocument.Bookmarks("EDIT4").Select
Selection.Range.Editors.Add wdEditorEveryone
ActiveDocument.Bookmarks("EDIT5").Select
Selection.Range.Editors.Add wdEditorEveryone
ActiveDocument.Bookmarks("EDIT6").Select
Selection.Range.Editors.Add wdEditorEveryone
' Save the file using bookmark names within the file name
ActiveDocument.SaveAs FileName:="Requirements - " & _
ActiveDocument.Bookmarks("PERSON").Range.Text & " - " & _
ActiveDocument.Bookmarks("COMPANY").Range.Text & ".docx"
' Close the document
ActiveDocument.Close
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Loop
End Sub
Many thanks in advance,
Ben