Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   Help - can't add "Item" (of type MailItem) using Attachments.Add() (http://www.outlookbanter.com/outlook-vba/22636-help-cant-add-item-type.html)

[email protected] August 2nd 06 05:37 PM

Help - can't add "Item" (of type MailItem) using Attachments.Add()
 
Hello,

Any suggestions on why I get a "Run Time Error '-1407020020
(a838838833)': Can't find this file. Make sure the path and file name
are correct." in the code below?

Public Sub Application_Startup()

' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems =
Outlook.Session.GetDefaultFolder(olFolderInbox).It ems

End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then

Dim mailToFwd As MailItem
Set mailToFwd = Item
'create a new message and address it
Dim myEmail As MailItem
Set myEmail = Application.CreateItem(olMailItem)
myEmail.To = "
myEmail.Subject = "FYI"
' attaching the file
myEmail.Attachments.Add (Item)
' now send the message
myEmail.Send

End If

End Sub


Michael Bauer [MVP - Outlook] August 3rd 06 06:55 AM

Help - can't add "Item" (of type MailItem) using Attachments.Add()
 
Am 2 Aug 2006 08:37:58 -0700 schrieb :

If you do not need the function result, i.e. the ref onto the added
attachment, then donīt write the brackets, but:

myEmail.Attachments.Add Item

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
--
www.VBOffice.net --


Hello,

Any suggestions on why I get a "Run Time Error '-1407020020
(a838838833)': Can't find this file. Make sure the path and file name
are correct." in the code below?

Public Sub Application_Startup()

' Reference the items in the Inbox. Because myOlItems is declared
' "WithEvents" the ItemAdd event will fire below.
Set myOlItems =
Outlook.Session.GetDefaultFolder(olFolderInbox).It ems

End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

' Check to make sure it is an Outlook mail message, otherwise
' subsequent code will probably fail depending on what type
' of item it is.
If TypeName(Item) = "MailItem" Then

Dim mailToFwd As MailItem
Set mailToFwd = Item
'create a new message and address it
Dim myEmail As MailItem
Set myEmail = Application.CreateItem(olMailItem)
myEmail.To = "
myEmail.Subject = "FYI"
' attaching the file
myEmail.Attachments.Add (Item)
' now send the message
myEmail.Send

End If

End Sub



All times are GMT +1. The time now is 08:39 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright Đ2004-2006 OutlookBanter.com