View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl Steve Yandl is offline
external usenet poster
 
Posts: 284
Default Add attachment to an already open Outlook email

Nathan,

This may be more complex than you suspect.

If you're talking about an email that is being worked on but not yet saved,
you will have to work with Inspector objects (a real pain in my opinion).
If you have an Outlook MailItem in the Drafts or Outbox folder you could
probably do what you want but you need to decide how you're going to select
the specific mail you want the attachment added to. There are similar
questions if you're talking about an email from someone else residing in the
Inbox folder where you would like to do a reply and add the attachment.


Steve Yandl



"Nathan Berton" wrote in message
...
Hi,

I'm trying to use Excel to add an attachment to an Outlook email
that's already been opened in Outlook. I have code that creates a new
email and adds the attachment, but I want to be able to preserve the
email chain in a reply or add the file after I've already written the
body of the email.

Any help is appreciated! Thanks! Here's the code I mentioned that I
already have:

Sub test()
Dim filename As String
Dim result As Long
Dim OutMail As Object
Dim OutApp As Object

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0) ' this is the line
I expect needs to be changed.


With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Emailing: " & ActiveWorkbook.Name
.Body = ""
.Attachments.Add Environ("temp") & "\zip\" &
Mid(ActiveWorkbook.Name, 1, Len(ActiveWorkbook.Name) - 4) & ".zip"
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub