Resetting Window back to Word at end of Macro

P

PiaD

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 = "(e-mail address removed)"
'Set the recipient for a copy
.CC = "(e-mail address removed)"
.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
 
D

Doug Robbins - Word MVP

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
 
G

Graham Mayor

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top