J
jeanmac
Hello all
I've been working on code to send a document as an Outlook attachment with a
specific Email address in the CC field. I've managed to do this pretty well
with help from this site. Everything appeared to be working well, and then
all of a sudden the Email message opens with a prompt to save it. I don't
want that prompt, I just want them to be able to write their Email. Does
anyone have an idea what's gone wrong? I'm attaching a copy of my code.
Thanks for all your help.
Sub Send_As_Mail_Attachment()
' 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
'Prompt the user to save the document
ActiveDocument.SaveAs ("")
' If Len(ActiveDocument.Path) = 0 Then
' MsgBox "Document needs to be saved first"
' Exit Sub
' End If
'unprotect the two protected sections of the document (need to do this
before protecting all)
ActiveDocument.Unprotect Password:="equities"
'protect the whole document as read only 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
ActiveDocument.Save
'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)"
'.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
'reset protection in the original document
ActiveDocument.Unprotect Password:="equities"
'original protection settings
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:="equities", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
End Sub
I've been working on code to send a document as an Outlook attachment with a
specific Email address in the CC field. I've managed to do this pretty well
with help from this site. Everything appeared to be working well, and then
all of a sudden the Email message opens with a prompt to save it. I don't
want that prompt, I just want them to be able to write their Email. Does
anyone have an idea what's gone wrong? I'm attaching a copy of my code.
Thanks for all your help.
Sub Send_As_Mail_Attachment()
' 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
'Prompt the user to save the document
ActiveDocument.SaveAs ("")
' If Len(ActiveDocument.Path) = 0 Then
' MsgBox "Document needs to be saved first"
' Exit Sub
' End If
'unprotect the two protected sections of the document (need to do this
before protecting all)
ActiveDocument.Unprotect Password:="equities"
'protect the whole document as read only 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
ActiveDocument.Save
'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)"
'.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
'reset protection in the original document
ActiveDocument.Unprotect Password:="equities"
'original protection settings
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Protect Password:="equities", NoReset:=False, Type:= _
wdAllowOnlyFormFields
ActiveDocument.Save
End Sub