poniedziałek, 4 stycznia 2010

excel - importowanie e-mail do TXT

1. Przechwytywanie przychodzących maili i ich zapis do pliku txt.
a) otwieramy Outlooka
b) wybieramy z opcji Edycja/ Makro / Edytor Visual Basic
c) następnie rozwijamy znajdujące się po lewej stronnie w edytorze Project/ Microsoft Office Outlook Objects/ ThisOutlookSession i wklejamy kod:

Private WithEvents TabelkaItems As Items
Private Sub Application_Startup()


On Error Resume Next
Set TabelkaItems = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox).Items


End Sub


Private Sub TabelkaItems_ItemAdd(ByVal Item As Object)


On Error Resume Next
Dim oMail As MailItem
Set oMail = Item
If oMail Is Nothing Then Exit Sub
With oMail


If InStr(1, .Body, "tabelk") > 0 Or _
InStr(1, .Subject, "tabelk") > 0 Then


Open "D:\aaaaaa\rental.txt" For Append As #1
Print #1, "data: " & Format(Now, "YYYY-MM-DD")
Print #1, "temat: " & .Subject
Print #1, "osoba: " & .SenderName
Print #1, "" & .SenderName; .Body
Close #1


End If
End With


Set oMail = Nothing
End Sub

autor: Piotr Czech /KIELCE

Brak komentarzy:

Prześlij komentarz