Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-01-2014, 11:01 AM
thundercats9595 thundercats9595 is offline Saving Emails to New Folder along with Attachments Windows 7 64bit Saving Emails to New Folder along with Attachments Office 2010 64bit
Novice
Saving Emails to New Folder along with Attachments
 
Join Date: Jan 2014
Posts: 7
thundercats9595 is on a distinguished road
Default

I tried to change up the code to trouble shoot my issue. Same problem though. Works fine when processing a singe email, but when processing multiple ones, ALL of the selected email attachments are placed in all of the newly created folders. Each email ends up in the right folder though.



Assistance is truly needed. Thank you.

Code:
Sub SaveIntoFoldersNew()
Dim Item As Object
Dim itm As Outlook.MailItem
Dim name As String
Dim Nname As String
Dim nFolder As String
Dim strFileName As String
Dim ItemsCount As Long
Dim ItemsAttachmentsCount As Long
Dim iSave As Long
Dim msg As String
Dim intIdx As Integer
Dim excApp As Object
Dim Exp As Outlook.Explorer
Dim sln As Outlook.Selection
 
 
   Set Exp = Application.ActiveExplorer
   Set sln = Exp.Selection
   If sln.Count = 0 Then
   MsgBox "No objects selected."
   Else
   myPath = "C:\Convert"
 
   Set itm = Outlook.ActiveExplorer.Selection.Item(1)
 
   For Each itm In sln
 
 
   If itm.Class = olMail Then
       If Nname = "" Then
       name = itm.Subject
       Else
 
       End If
' Cleanse illegal characters from subject... :/|*?<>" etc
       name = Replace(name, "<", "(")
       name = Replace(name, ">", ")")
       name = Replace(name, "&", "n")
       name = Replace(name, "%", "pct")
       name = Replace(name, """", "'")
       name = Replace(name, "´", "'")
       name = Replace(name, "`", "'")
       name = Replace(name, "{", "(")
       name = Replace(name, "[", "(")
       name = Replace(name, "]", ")")
       name = Replace(name, "}", ")")
       name = Replace(name, "  ", "_")
       name = Replace(name, "   ", "_")
       name = Replace(name, "  ", "_")
       name = Replace(name, "..", "_")
       name = Replace(name, ".", "_")
       name = Replace(name, "__", "_")
       name = Replace(name, ": ", "_")
       name = Replace(name, ":", "_")
       name = Replace(name, "/", "_")
       name = Replace(name, "\", "_")
       name = Replace(name, "*", "_")
       name = Replace(name, "?", "_")
       name = Replace(name, """", "_")
       name = Replace(name, "__", "_")
       name = Replace(name, "|", "_")
 
 
           If myPath = False Then
               MsgBox "No directory chosen !", vbExclamation
           Else
 
               nFolder = myPath & "\" & name & "\"
               MkDir nFolder
 
               itm.SaveAs nFolder & "00_Email " & name & ".mht", olMHTML
 
For iSave = 1 To ActiveExplorer.Selection.Count
 
   Set Item = ActiveExplorer.Selection(iSave)
 
If TypeOf Item Is MailItem Or TypeOf Item Is PostItem Then
       ItemsCount = ItemsCount + 1
       For Each ItemAttachment In Item.Attachments
           ItemsAttachmentsCount = ItemsAttachmentsCount + 1
           ' Get the file name.
           strFileName = ItemAttachment.FileName
 
           ' Save the attachment as a file.
           ItemAttachment.SaveAsFile nFolder & strFileName
       Next ItemAttachment
 
   End If
 
 
           Item.Close olDiscard
           Set Item = Nothing
       Next
 
 
           End If
       Else
           MsgBox "You have not saved"
       End If
 
  Next itm
 
 End If
End Sub
Reply With Quote
  #2  
Old 02-01-2014, 12:32 PM
thundercats9595 thundercats9595 is offline Saving Emails to New Folder along with Attachments Windows 7 64bit Saving Emails to New Folder along with Attachments Office 2010 64bit
Novice
Saving Emails to New Folder along with Attachments
 
Join Date: Jan 2014
Posts: 7
thundercats9595 is on a distinguished road
Default Figured it out.

Had to change a line to;

For Each ItemAttachment In itm.Attachments

Reply With Quote
Reply

Tags
create folder, exporting, save attachments



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to access attachments on older emails charon Outlook 0 10-31-2013 05:52 AM
After rebuilding main identity NO attachments in SENT folder Manem Outlook 0 08-20-2012 10:43 AM
Saving Emails to New Folder along with Attachments Failsafe for saving email attachments?? AMH Word 1 06-14-2012 03:28 AM
Saving Emails to New Folder along with Attachments Printing Emails and attachments glow worm Outlook 1 06-28-2011 12:06 AM
Saving file attachments Chief96 Outlook 0 12-01-2005 11:28 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft