Outlook附件相关应用程序中的VB错误 [英] VB error in outlook attachment related application

查看:99
本文介绍了Outlook附件相关应用程序中的VB错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了以下用于Outlook的代码,识别电子邮件,保存附件,将电子邮件移动到子文件夹

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
    ' Declare variables
    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 Item As Outlook.Items
    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")
    
  
    'Set oc = Application.ActiveInspector.CurrentItem
    i = 0
    
' Check Inbox for messages and exit if none found
    If Inbox.Items.Count = 0 Then
        MsgBox "There are no messages in the Inbox.", vbInformation, _
               "Nothing Found"
        Exit Sub
    End If
    
' Check each message for attachments
    For Each Item In Inbox.Items
' Save any attachments found
        For Each Atmt In Item.Attachments
        ' This filename path must exist! Change folder name as necessary.
            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
            'Atmt.SaveAsFile FileName
            
            If get_bank(sender) <> "unknown" Then
            Atmt.SaveAsFile FileName
            Item.Move myDestFolder
              i = i + 1
            'Set Item = Item.FindNext
            End If
           
         Next Atmt
    Next Item
    
  ' Show summary message
    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
' Clear memory
GetAttachments_exit:
    Set Atmt = Nothing
    Set Item = Nothing
    Set ns = Nothing
    Set appOl = Nothing
    Exit Sub
' Handle errors
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



然后导入以下程序集
导入Microsoft.Office.Interop.Outlook
导入System.Net.Mime.MediaTypeNames
导入Microsoft.Office.Interop

但仍然出现以下错误



错误1应用程序"在命名空间"Microsoft.Office.Interop.Outlook"中不明确. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 16 26 WindowsApplication1
错误2"NameSpace"在命名空间"Microsoft.Office.Interop.Outlook"中不明确. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 17 19 WindowsApplication1
错误3"MAPIFolder"在命名空间"Microsoft.Office.Interop.Outlook"中不明确. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 18 22 WindowsApplication1
错误4"MAPIFolder"在命名空间"Microsoft.Office.Interop.Outlook"中不明确. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 19 29 WindowsApplication1
错误5附件"在命名空间"Microsoft.Office.Interop.Outlook"中不明确. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 22 21 WindowsApplication1
错误6项"在命名空间"Microsoft.Office.Interop.Outlook"中是不明确的. D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 27 22 WindowsApplication1
错误7未声明名称"olFolderInbox". D:\ MIT \ project \ Outlook 2007 \ WindowsApplication1 \ WindowsApplication1 \ Form1.vb 30 37 WindowsApplication1


我正在使用12.0办公室图书馆
请告诉我y是我如何防止它



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

推荐答案

尝试在此行中完全合格的Outlook.Application:
Try fully qualifying Outlook.Application in this line:
Dim appOl As New Outlook.Application


要说:


To say:

Dim appOl As New Microsoft.Office.Interop.Outlook.Application


这篇关于Outlook附件相关应用程序中的VB错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆