将变量声明为Outlook 2003中的文件夹会生成未定义的编译错误用户定义类型

时间:2017-01-13 23:37:32

标签: vba outlook-vba outlook-2003

我将收到的物品保存在硬盘上并以不同方式命名。

尝试将项目重新导入Outlook会出现错误:

  

编译错误用户定义类型未定义。

  

Dim Savefolder As Outlook.Folder

在我的第一个模块中

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
    Dim objAtt As Outlook.Attachment
    Dim Savefolder As String
    Savefolder = "c:\temp"
    For Each objAtt In itm.Attachments
        stFileName = Savefolder & "\" & objAtt.DisplayName
        i = 0
JumpHere:
        If Dir(stFileName) = "" Then
            objAtt.SaveAsFile stFileName
        Else
            i = i + 1
            stFileName = Savefolder & "\" & objAtt.DisplayName & " - " & i
            GoTo JumpHere
        End If
        Set objAtt = Nothing
    Next
End Sub

在我的第二个模块中

Sub ImportMessagesInFolder()
    Dim fso As Scripting.FileSystemObject
    Dim SourceFolder As Scripting.Folder
    Dim SourceFolderName As String
    Dim FileItem As Scripting.file
    Dim strFile, strFileType As String
    Dim oMsg As Object
    Dim copiedMsg As MailItem
    Dim Savefolder As Outlook.Folder

    Set fso = New Scripting.FileSystemObject
'Source folder
    SourceFolderName = "C:\temp"
    Set SourceFolder = fso.GetFolder(SourceFolderName)

'Set the Outlook folder name
    Set Savefolder = Session.GetDefaultFolder(olFolderInbox).Folders("Extra")
    Set Savefolder = Application.ActiveExplorer.CurrentFolder

    For Each FileItem In SourceFolder.Files

        Set oMsg = Session.OpenSharedItem(FileItem.Path)
        On Error Resume Next

        Set copiedMsg = oMsg.Copy
        copiedMsg.Move Savefolder

        Set copiedMsg = Nothing
        oMsg.Delete
        Set oMsg = Nothing

    Next FileItem

    Set FileItem = Nothing
    Set SourceFolder = Nothing
    Set fso = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

改为使用Outlook.MAPIFolder