Saving Item.body and item.attachment 
Author Message
 Saving Item.body and item.attachment

Hello,

maybe someone can help me fix this problem.
I get everyday a mail from one person with an body and  an attachment.
I want to save the body and the attachment in 2 different files.
Where are my faults in this code?
Sorry for my worth english

Thank you, Alex

Public WithEvents myOlItems As Outlook.Items

Public Sub Application_Startup()
   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)

 If Item.SenderName = "testperson" Then
        Item.Body.SaveAs "D:\Temp\test1.txt", olTXT
        Item.Attachments.SaveAsFile "D:\Temp\test2.txt", olTXT
  End If

End Sub



Sat, 18 Jan 2003 03:00:00 GMT  
 Saving Item.body and item.attachment
Modified code coming at ya.

If Item.Sender = "testperson" then
  Item.SaveAs "D:\Temp\test1.txt", olTXT
  Item.Attachments.Item(1).SaveAsFile "D:\Temp\" & _
    Item.Attachments.Item(1).DisplayName
End If

While I didn't test the code the Attachments line might give you problems.
If it does, post back and one of the group memebers can clean it up for you.


Quote:
> Hello,

> maybe someone can help me fix this problem.
> I get everyday a mail from one person with an body and  an attachment.
> I want to save the body and the attachment in 2 different files.
> Where are my faults in this code?
> Sorry for my worth english

> Thank you, Alex

> Public WithEvents myOlItems As Outlook.Items

> Public Sub Application_Startup()
>    Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
> End Sub

> Private Sub myOlItems_ItemAdd(ByVal Item As Object)

>  If Item.SenderName = "testperson" Then
>         Item.Body.SaveAs "D:\Temp\test1.txt", olTXT
>         Item.Attachments.SaveAsFile "D:\Temp\test2.txt", olTXT
>   End If

> End Sub



Sun, 19 Jan 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Paste item (not contents) into body of another item

2. Removal of attachments on email items in Sent items folder

3. Open Mail Item and Save Attachments

4. help saving items in combo box items

5. How .Items(5) + .Items.Item(5) ?

6. Saving Body Text From Attachments

7. changing Item.body when msg sent

8. How to select text in Item.Body (solution)

9. Newbie question: text inserted into body of a mail item is lost when sendin Outlook 2002

10. FInding the Body Text in a Report Item

11. Using color when setting an appointment items body

12. Copy viewed items from one folder into email body

 

 
Powered by phpBB® Forum Software