Hi there -
I have two issues I would like to resolve for this macro:
1) I would like to reset the Window back to Word (from Outlook) after the
macro runs. It currently stays in Outlook after it is run. This would be
confusing to the user.
2)I would like to know if I can make the .CC property a variable that can
always retrieve and copy the current user email address in the cc field of
the email.

Below is the the code I am using:

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 prior to running this step. Use MS
Word Menu: File->Save As."
Exit Sub
End If

Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
.To = "somebody@mail.com"
'Set the recipient for a copy
.CC = "currentuseremail@mail.com"
.Subject = "New Document"
'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:="New Document.doc"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Send
End With

If bStarted Then
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub

Re: Resetting Window back to Word at end of Macro by Doug

Doug
Wed May 07 23:53:39 PDT 2008

The focus never leaves the active document when I run that code.

You can certainly make the CC property a variable (as long as it contains a
valid email address). It is just a matter of the code the retrieve the
email address to be loaded into that variable.

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

"PiaD" <PiaD@discussions.microsoft.com> wrote in message
news:03F7096A-D922-48F7-BDA5-F51229F87741@microsoft.com...
> Hi there -
> I have two issues I would like to resolve for this macro:
> 1) I would like to reset the Window back to Word (from Outlook) after the
> macro runs. It currently stays in Outlook after it is run. This would be
> confusing to the user.
> 2)I would like to know if I can make the .CC property a variable that can
> always retrieve and copy the current user email address in the cc field of
> the email.
>
> Below is the the code I am using:
>
> 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 prior to running this step. Use MS
> Word Menu: File->Save As."
> Exit Sub
> End If
>
> Set oOutlookApp = GetObject(, "Outlook.Application")
> If Err <> 0 Then
> Set oOutlookApp = CreateObject("Outlook.Application")
> bStarted = True
> End If
>
> Set oItem = oOutlookApp.CreateItem(olMailItem)
>
> With oItem
> .To = "somebody@mail.com"
> 'Set the recipient for a copy
> .CC = "currentuseremail@mail.com"
> .Subject = "New Document"
> '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:="New Document.doc"
> 'The content of the document is used as the body for the email
> .Body = ActiveDocument.Content
> .Send
> End With
>
> If bStarted Then
> oOutlookApp.Quit
> End If
> 'Clean up
> Set oItem = Nothing
> Set oOutlookApp = Nothing
>
> End Sub



Re: Resetting Window back to Word at end of Macro by Graham

Graham
Thu May 08 00:37:10 PDT 2008

It shouldn't activate Outlook as a foreground task. Running the macro merely
sends the message or drops it in Outlook's outbox depending on whether you
have Outlook set to send mails immediately or not.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


PiaD wrote:
> Hi there -
> I have two issues I would like to resolve for this macro:
> 1) I would like to reset the Window back to Word (from Outlook) after
> the macro runs. It currently stays in Outlook after it is run. This
> would be confusing to the user.
> 2)I would like to know if I can make the .CC property a variable that
> can always retrieve and copy the current user email address in the cc
> field of the email.
>
> Below is the the code I am using:
>
> 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 prior to running this step. Use
> MS Word Menu: File->Save As."
> Exit Sub
> End If
>
> Set oOutlookApp = GetObject(, "Outlook.Application")
> If Err <> 0 Then
> Set oOutlookApp = CreateObject("Outlook.Application")
> bStarted = True
> End If
>
> Set oItem = oOutlookApp.CreateItem(olMailItem)
>
> With oItem
> .To = "somebody@mail.com"
> 'Set the recipient for a copy
> .CC = "currentuseremail@mail.com"
> .Subject = "New Document"
> '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:="New Document.doc"
> 'The content of the document is used as the body for the email
> .Body = ActiveDocument.Content
> .Send
> End With
>
> If bStarted Then
> oOutlookApp.Quit
> End If
> 'Clean up
> Set oItem = Nothing
> Set oOutlookApp = Nothing
>
> End Sub