I save items I receive on my hard drive and name them differently.
Trying to import the items back into Outlook gives me an error:
Compile Error User-Defined type not defined.
on
Dim Savefolder As Outlook.Folder
In my first module
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
In my second module
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
Use Outlook.MAPIFolder
instead.