J
jeanmac
Hello
I wonder if anyone could help me with this. I haven't done much programming
full stop, and even less in Word. What I want to do is send a Word document
based on a template as an attachment in Outlook. However, I want the cc
field to always have the same email address in it. In addition to this I
would like the users to be able to choose who they want to send to from their
address list, add any other cc addresses and then type what they want in the
subject and body of the message. The only code I have found so far can
either prompt for an Email address or hard code one and then send the
message. I want to open the message so that they can edit it before sending.
Can anyone help? I'd really appreciate that.
The code I have so far is:
Sub SendDocumentAsAttachment()
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"
.Send
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
I wonder if anyone could help me with this. I haven't done much programming
full stop, and even less in Word. What I want to do is send a Word document
based on a template as an attachment in Outlook. However, I want the cc
field to always have the same email address in it. In addition to this I
would like the users to be able to choose who they want to send to from their
address list, add any other cc addresses and then type what they want in the
subject and body of the message. The only code I have found so far can
either prompt for an Email address or hard code one and then send the
message. I want to open the message so that they can edit it before sending.
Can anyone help? I'd really appreciate that.
The code I have so far is:
Sub SendDocumentAsAttachment()
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"
.Send
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