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 = "emailaddress@thisemail.com"
'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

Re: Document as Outlook Attachment by Perry

Perry
Mon Feb 05 16:03:41 CST 2007

> message. I want to open the message so that they can edit it before
> sending.

Apart from all the other things you'd like to do in yr msg, replace .Send by
.Display
like examplified below.
This way, the msg will remain onscreen for the user to edit. This sounds
like the abovequoted, imo.

'Replace this
With oItem
'all the other things to oItem
.Send
End With
'end replace

by this
With oItem
'all the other things to oItem
.Send
End With
'end by

Krgrds,
Perry

"jeanmac" <jeanmac@discussions.microsoft.com> wrote in message
news:C3E83709-D371-4E95-9685-5FE2ABD1455B@microsoft.com...
> 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 = "emailaddress@thisemail.com"
> '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
>
>


Re: Document as Outlook Attachment by jeanmac

jeanmac
Mon Feb 05 16:34:01 CST 2007

Thank you so much!!! I've tried all sorts of ways out, but didn't think of
Display. Without people like you, people like me would continue to be in the
dark. I wish I had your brain...

Jeanmac

"Perry" wrote:

> > message. I want to open the message so that they can edit it before
> > sending.
>
> Apart from all the other things you'd like to do in yr msg, replace .Send by
> .Display
> like examplified below.
> This way, the msg will remain onscreen for the user to edit. This sounds
> like the abovequoted, imo.
>
> 'Replace this
> With oItem
> 'all the other things to oItem
> .Send
> End With
> 'end replace
>
> by this
> With oItem
> 'all the other things to oItem
> .Send
> End With
> 'end by
>
> Krgrds,
> Perry
>
> "jeanmac" <jeanmac@discussions.microsoft.com> wrote in message
> news:C3E83709-D371-4E95-9685-5FE2ABD1455B@microsoft.com...
> > 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 = "emailaddress@thisemail.com"
> > '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
> >
> >
>