PDA

View Full Version : move email from a frolder to different folder from Desktop



IonutC
07-19-2016, 06:57 AM
Hi guys,

If I want to save/copy all the files from an OutlookFolder to a folder from Desktop, how can I do that?

I have this code, but because my DestFolderpAth is on "C:\Data\SR_PIXEL_Error_emails" I can;t save this.
How can I make this code to copy all my emails there?


For Each oitem In myItems.Restrict("[UnRead] = True")
oitem.Save (DestFolderPath)

Next



My entire code is:


'set outlook objectsSet olapp = CreateObject("Outlook.Application")
Set olappns = olapp.GetNamespace("MAPI")
Set oinbox = olappns.GetDefaultFolder(6)
' folder to scan
Set oinbox = oinbox.Folders("2.3.1 ERROR: Pixel Comp - SR")


' check if any unread email in folder name " 2.3.1 ERROR: Pixel Comp - SR"
If oinbox.Items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "NO Unread Email In Inbox"
Exit Sub
End If


' sort emails on recieved basis
Set myItems = oinbox.Items
myItems.Sort "[Received]", True


' creare de foldere
Set fso = CreateObject("Scripting.FileSystemObject")
DestFolderPath = "C:\Data\SR_PIXEL_Error_emails"
If Not fso.FolderExists(DestFolderPath) Then
fso.CreateFolder (DestFolderPath)


End If


'loop through all unread emails
'Set objcopy = oitem.Copy


For Each oitem In myItems.Restrict("[UnRead] = True")
oitem.Move (DestFolderPath)


Next