M
Mota
Hello;
I copied this code from the NewsGroup(thanx to its provider),and in
Microsoft outlook,double clicked on "ThisOutlookSession",and pasted it in
the opening module.So i expected when a mail having an Attachment
receives,automatically be saved in the StrPath,difined in SaveAttachment
function as its argument.
But when a mail arrives,nothing happens and no error occures.I think the
triggered Event doesnt occure.what i have to do to do so,or which seetings
may be wrong in my MS Outlook?I program in MS Access and familiar with VBA
coding,but not in Outlook Events,Collections and.....
Can anyone please help me?
Thank you in advance.
Private Sub Application_NewMail()
' Occurs when one or more new messages are received in the Inbox
SaveAttachments "E:\PrescPro\ReceivedFiles", "My Virtual Server"
End Sub
Public Sub SaveAttachments(strExportPath As String, strFrom As String)
' Declare objects
Dim olNameSpace As Outlook.NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim olAttach As Outlook.Attachment
Dim olItem As Object
Set olNameSpace = Application.GetNamespace("MAPI")
' Get the default inbox
Set olInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
' Loop on the items collection from the inbox folder
For Each olItem In olInbox.Items
' Check if the item is a mail (could be a task, etc.)
If olItem.Class = olMail Then
' Check the sender name and unread status
' Check if there are attachments
If olItem.Attachments.Count > 0 Then
For Each olAttach In olItem.Attachments
' Save attachments
olAttach.SaveAsFile strExportPath & _
"\" & olAttach.FileName
Next
' Move the item to the deleted folder
olItem.Delete
End If
End If
Next
Set olItem = Nothing
Set olInbox = Nothing
Set olNameSpace = Nothing
End Sub
I copied this code from the NewsGroup(thanx to its provider),and in
Microsoft outlook,double clicked on "ThisOutlookSession",and pasted it in
the opening module.So i expected when a mail having an Attachment
receives,automatically be saved in the StrPath,difined in SaveAttachment
function as its argument.
But when a mail arrives,nothing happens and no error occures.I think the
triggered Event doesnt occure.what i have to do to do so,or which seetings
may be wrong in my MS Outlook?I program in MS Access and familiar with VBA
coding,but not in Outlook Events,Collections and.....
Can anyone please help me?
Thank you in advance.
Private Sub Application_NewMail()
' Occurs when one or more new messages are received in the Inbox
SaveAttachments "E:\PrescPro\ReceivedFiles", "My Virtual Server"
End Sub
Public Sub SaveAttachments(strExportPath As String, strFrom As String)
' Declare objects
Dim olNameSpace As Outlook.NameSpace
Dim olInbox As Outlook.MAPIFolder
Dim olAttach As Outlook.Attachment
Dim olItem As Object
Set olNameSpace = Application.GetNamespace("MAPI")
' Get the default inbox
Set olInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
' Loop on the items collection from the inbox folder
For Each olItem In olInbox.Items
' Check if the item is a mail (could be a task, etc.)
If olItem.Class = olMail Then
' Check the sender name and unread status
' Check if there are attachments
If olItem.Attachments.Count > 0 Then
For Each olAttach In olItem.Attachments
' Save attachments
olAttach.SaveAsFile strExportPath & _
"\" & olAttach.FileName
Next
' Move the item to the deleted folder
olItem.Delete
End If
End If
Next
Set olItem = Nothing
Set olInbox = Nothing
Set olNameSpace = Nothing
End Sub