hi i get following code for Outlook, Recognise Email, Save Attachment, Move Email To A Subfolder
Option Explicit
Sub GetAttachments_From_Inbox()
On Error GoTo GetAttachments_err
Dim appOl As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim myDestFolder As Outlook.MAPIFolder
Dim Item As Object
Dim Atmt As Outlook.Attachment
Dim FileName As String
Dim i As Integer
Dim sender As String
Dim ext As String
Dim Items As Outlook.Items
Dim oc As Object
Set ns = appOl.GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set Item = Inbox.Items
Set myDestFolder = Inbox.Folders("Personal Mail")
i = 0
If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, _
"Nothing Found"
Exit Sub
End If
For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
sender = Atmt.Parent.SenderEmailAddress
sender = Right(sender, Len(sender) - InStrRev(sender, "="))
ext = Atmt.FileName
ext = Right(ext, Len(ext) - InStrRev(ext, ".") + 1)
FileName = "S:\Loans\Data\For\Outlook\" & get_bank(sender) & ext
If get_bank(sender) <> "unknown" Then
Atmt.SaveAsFile FileName
Item.Move myDestFolder
i = i + 1
End If
Next Atmt
Next Item
If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them into the C:\Email Attachments folder." _
& vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!"
Else
MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!"
End If
GetAttachments_exit:
Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing
Set appOl = Nothing
Exit Sub
GetAttachments_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume GetAttachments_exit
End Sub
Function get_bank(sender As String) As String
Select Case sender
Case "ABC.DEF@COMPANYNAME.com"
get_bank = "ABC"
Case Else
get_bank = "unknown"
End Select
End Function
then import following assemblies
Imports Microsoft.Office.Interop.Outlook
Imports System.Net.Mime.MediaTypeNames
Imports Microsoft.Office.Interop
but still getting following errors
Error 1 'Application' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 16 26 WindowsApplication1
Error 2 'NameSpace' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 17 19 WindowsApplication1
Error 3 'MAPIFolder' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 18 22 WindowsApplication1
Error 4 'MAPIFolder' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 19 29 WindowsApplication1
Error 5 'Attachment' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 22 21 WindowsApplication1
Error 6 'Items' is ambiguous in the namespace 'Microsoft.Office.Interop.Outlook'. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 27 22 WindowsApplication1
Error 7 Name 'olFolderInbox' is not declared. D:\MIT\project\Outlook 2007\WindowsApplication1\WindowsApplication1\Form1.vb 30 37 WindowsApplication1
i am using 12.0 office library
pls tell me y is that and how can i prevent it