Attaching mail items in Outlook 2010

Status
Not open for further replies.
A

Alex K

The code below works with Outlook 2007, but fails with Outlook 2010 RTM. The

"objAttachments.Add" line throws the following error:

-------------------------
Run-time error '-2147221233 (8004010f)':

The attempted operation failed. An object could not be found.

-------------------------
Any ideas on a workaround?

Sub AddAttachment()

Dim objItem As Outlook.MailItem

Dim objAttachments As Outlook.Attachments

Dim objItemAtt As Outlook.MailItem

Set objItem = Application.CreateItem(olMailItem)

Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)

Set objAttachments = objItem.Attachments

objAttachments.Add objItemAtt, Outlook.olEmbeddeditem, 1, "foo"

objItem.Display

End Sub

Thank you in advance,

ak
 
K

Ken Slovak - [MVP - Outlook]

See if it works better calling that as a function, setting an Attachment

object as the return value.

"Alex K" <AlexK> wrote in message

news:53255CD8-92CE-4F0A-B18A-0A19A6A325AF@microsoft.com...
> The code below works with Outlook 2007, but fails with Outlook 2010 RTM.
> The
> "objAttachments.Add" line throws the following error:
> -------------------------> Run-time error '-2147221233 (8004010f)':

> The attempted operation failed. An object could not be found.
> -------------------------
> Any ideas on a workaround?

> Sub AddAttachment()
> Dim objItem As Outlook.MailItem
> Dim objAttachments As Outlook.Attachments
> Dim objItemAtt As Outlook.MailItem

> Set objItem = Application.CreateItem(olMailItem)
> Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
> Set objAttachments = objItem.Attachments
> objAttachments.Add objItemAtt, Outlook.olEmbeddeditem, 1, "foo"
> objItem.Display
> End Sub

> Thank you in advance,
> ak
 
A

Alex K

Do you mean like this:

Sub AddAttachment()

Dim objItem As Outlook.MailItem

Dim objAttachments As Outlook.Attachments

Dim objItemAtt As Outlook.MailItem

Dim objAtt As Outlook.Attachment

Set objItem = Application.CreateItem(olMailItem)

Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)

Set objAttachments = objItem.Attachments

Set objAtt = objAttachments.Add(objItemAtt, Outlook.olEmbeddeditem, 1,

"foo")

objItem.Display

End Sub

Same exact result. What else can I try?

Thanks a lot for your help.

ak
wrote:


> See if it works better calling that as a function, setting an Attachment
> object as the return value.
 
K

Ken Slovak - [MVP - Outlook]

I verified that this doesn't work in Outlook 2010 RTM. I'll report it to the

product group.

As a workaround save the selected message as an MSG file, then attach the

MSG file. That seems to work.

"Alex K" <AlexK> wrote in message

news:A3E1B6CC-BE46-4C90-BAFF-7D2C44D65D88@microsoft.com...
> Do you mean like this:

> Sub AddAttachment()
> Dim objItem As Outlook.MailItem
> Dim objAttachments As Outlook.Attachments
> Dim objItemAtt As Outlook.MailItem
> Dim objAtt As Outlook.Attachment

> Set objItem = Application.CreateItem(olMailItem)
> Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
> Set objAttachments = objItem.Attachments
> Set objAtt = objAttachments.Add(objItemAtt, Outlook.olEmbeddeditem, 1,
> "foo")
> objItem.Display
> End Sub

> Same exact result. What else can I try?

> Thanks a lot for your help.
> ak
 
K

Ken Slovak - [MVP - Outlook]

What is your configuration for testing? Are you using Exchange mailbox

accounts (if so are they cached or online), are you using PST files? What

OS's did you test on?
<kenslovak@mvps.org> wrote in message

news:ebzp4Q96KHA.356@TK2MSFTNGP05.phx.gbl...
> I verified that this doesn't work in Outlook 2010 RTM. I'll report it to
> the product group.

> As a workaround save the selected message as an MSG file, then attach the
> MSG file. That seems to work.

> >

>

> "Alex K" <AlexK> wrote in message
> news:A3E1B6CC-BE46-4C90-BAFF-7D2C44D65D88@microsoft.com...
> > Do you mean like this:
>

>> Sub AddAttachment()
> > Dim objItem As Outlook.MailItem
> > Dim objAttachments As Outlook.Attachments
> > Dim objItemAtt As Outlook.MailItem
> > Dim objAtt As Outlook.Attachment
>

>> Set objItem = Application.CreateItem(olMailItem)
> > Set objItemAtt = Application.ActiveExplorer.Selection.Item(1)
> > Set objAttachments = objItem.Attachments
> > Set objAtt = objAttachments.Add(objItemAtt, Outlook.olEmbeddeditem, 1,
> > "foo")
> > objItem.Display
> > End Sub
>

>
>> Same exact result. What else can I try?
>

>> Thanks a lot for your help.
> > ak

>
 
K

Ken Slovak - [MVP - Outlook]

In further testing both by me and by the Outlook product group, it appears

that the code will work in Outlook 2010 if you are using Exchange mailboxes,

not with PST files.

So the code can run as is with mailboxes, with a PST store provider you'd

need to use the workaround I provided.

I'll see if I can get this on a fix list for SP1, and get it documented.
<kenslovak@mvps.org> wrote in message

news:eQYPEPI7KHA.2220@TK2MSFTNGP04.phx.gbl...
> What is your configuration for testing? Are you using Exchange mailbox
> accounts (if so are they cached or online), are you using PST files? What
> OS's did you test on?

> >

>

>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
H attaching e-mails to new e-mail using VBA Outlook VBA and Custom Forms 1
R Shortcut for attaching the same file repeatedly Using Outlook 6
M re-Attaching PSTs after upgrade to 2016 Using Outlook 0
P Outlook Randomly Not attaching (attachment file) Using Outlook 0
D Attaching date named files Using Outlook 3
L Creating a Task from Email and Attaching Original Email Outlook VBA and Custom Forms 6
D Attaching email conversations to tasks Using Outlook 2
J Attaching Files to Outlook Outlook VBA and Custom Forms 1
D Tab Order Out of Sequence After Attaching Document Outlook VBA and Custom Forms 1
R Sent emails show iCloud mail account not the alias Using Outlook 1
D Advanced e-Mail search on from/to contact group only searches for first 20 contacts in group Using Outlook 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 5
P Importing other e-mail accounts into Outlook Using Outlook 1
lcarpay Stay in the mail folder pane after ctrl-1 Using Outlook 1
O Exchange Sync period only (e.g. last years mail) Using Outlook 0
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
M Convertor for Outlook Express Mail Store (.dbx) to Outlook Mail Store (.pst) Using Outlook 0
T vba extract data from msg file as attachment file of mail message Outlook VBA and Custom Forms 1
J E-mail held in Outbox while Minimized Using Outlook 3
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
T Outlook creates a copie of every mail I send Using Outlook.com accounts in Outlook 4
N Please advise code received new mail Using Outlook 0
M Outlook 2010 How could I globally redesign an outlook template form/region/inspector template used to display mail lists or an individual mails? Outlook VBA and Custom Forms 0
A How to stop user form from disapearing once mail window is closed? Outlook VBA and Custom Forms 0
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
R How to Sync *all* Google Workspace Mail Folders with Outlook 2019 (MS365) Using Outlook 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
L Correct E-Mail Pulling Wrong Mail Using Outlook 5
S Outlook mail adressing stops after first match in GAL Using Outlook 0
P Outlook 2013 All imported Mail Rules in error when imported into new profile Using Outlook 5
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
MrMayor SENT mail not reloading to top?? Using Outlook 4
Terry Sullivan Sender Field Displays My E-Mail Address, Not My Name Using Outlook 1
ThinkToday Calculate reply time of outlook mail Using Outlook 1
B Outlook 2010 Opening Mail Attachment Using Outlook 2
e_a_g_l_e_p_i Is it possible it set the fonts used to read incoming mail Using Outlook 25
D Mail in Sent Items Gone Using Outlook 12
M Managing Gmail "All Mail" sync issues with IMAP Using Outlook 1
GregS Outlook 2016 Sent Mail absent from Sent Mail or Sent Items Folders Using Outlook 4
GregS Why is Outlook 2016 mail in Outlook.com? Using Outlook 1
S Outlook not receiving mail Using Outlook 1
Commodore Outlook (2013) issues with icloud.com mail Using Outlook 0
GregS Outlook 2016 iPhone won't download Outlook 2016 Mail. Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
oliv- How to distinguish whether mail is incoming or outgoing? Outlook VBA and Custom Forms 2
W Receiving mail for account that has been deleted Using Outlook 2
H In outlook 365 POP mail Inbox, email takes a long time or never arrives. Using Outlook 1

Similar threads

Top