J
jeanmac
I need to send a docoment directly from Word as an Outlook attachment with a
specific address in the cc field. I have managed to do this with help.
However, the users do not want to save the document before sending. Can I
amend the code to reflect that? Would really appreciate the help. The code I
have is:
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 = "MyEmail.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"
.Display
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
specific address in the cc field. I have managed to do this with help.
However, the users do not want to save the document before sending. Can I
amend the code to reflect that? Would really appreciate the help. The code I
have is:
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 = "MyEmail.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"
.Display
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