Protecting a Word doc sent as an attachment

J

jeanmac

Hello

Thanks everyone for your help so far in my efforts to send a document as an
Email attachment.

I have to protect the attached document so that it cannot b changed at the
other end. I wrote code to protect the document in the macro, but it
protects the document at this end and leaves the attachment unprotected.
Help!!! I'm climbing the walls now. My code is:

Sub Send_As_Mail_Attachment()

'unprotect the two protected sections of the document (need to do this
before protecting all)
ActiveDocument.Unprotect Password:="equities"

'protect the document before sending
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:="equities", NoReset:=False, Type:= _
wdAllowOnlyFormFields

' send the document as an attachment in an Outlook Email message
Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

If Len(ActiveDocument.Path) = 0 Then
MsgBox "Document needs to be saved first"
Exit Sub
End If

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")

'Outlook wasn't running, start it from code
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
'Set the recipient for a copy
.CC = "(e-mail address removed)"
'Add the document as an attachment, you can use the .displayname
property
'to set the description that's used in the message
.Attachments.Add Source:=ActiveDocument.FullName,
Type:=olByValue, _
DisplayName:="Document as attachment"
.Display
End With

'If we started Outlook from code, then close it
If bStarted Then
oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing


End Sub
 
D

Doug Robbins - Word MVP

Your code is not saving the document after protecting it. As a result, the
one that you are attaching is the previously saved, unprotected version. I
would suggest however that you convert the documnet to a .pdf file and send
that.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

jeanmac

Hi Doug

Thanks for your reply, that makes sense. We would prefer to pdf the
document rahter than protecting it, however I didn't think I could do that
from code because the pdf format is Adobe Acrobat. The people involved just
want to press a button and bang it's gone. Is there any way that it can be
converted to pdf in the code? They all have Acrobat.

Thanks for all your help
Jean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top