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
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