2017-01-13 76 views
0

調試時出現代碼錯誤。我正在尋找保存我在硬盤上收到的物品,並以不同的方式命名它們。這我沒有問題。嘗試將.msg移回Outlook時出現代碼錯誤

當我試圖將它們導入到Outlook中時,出現了我的問題。它給我一個錯誤:編譯錯誤用戶定義類型沒有定義。在特定的線上。

這裏是我的代碼:

在我的第一模塊

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 

我也激活了Microsoft腳本運行時參考。第一個模塊工作正常,並用特定名稱保存附件,但第二個模塊得到錯誤:

Dim Savefolder As Outlook.Folder 

任何幫助表示讚賞線

沒有定義編譯錯誤用戶定義類型!

回答

0

改爲使用Outlook.MAPIFolder

+0

這解決了我的問題,但現在我得到一個問題:設置oMsg = Session.OpenSharedItem(FileItem.Path) 它聲明何時運行宏:運行時error438對象不支持此屬性或方法 –

+0

什麼版本Outlook使用? –

+0

Outlook 2003 @Dmitry Streblechenko –

相關問題