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