![]() |
#1
|
|||
|
|||
![]()
Hi ALL,
In Outlook 2016 is there any way to save a group of e-mails but with each e-mail being saved as an individual file. I know when I'm reading a specific e-mail I can save it as an individual file which I can later double click on to read without going into Outlook. But I would like to save all the e-mails within a folder but with each e-mail as an individual file. The only way I've found to save a folder of e-mails is with the Import/Export option but the folder is saved as a .pst file and the only way to read an individual e-mail within the saved file is to import the file into Outlook and then look for that specific e-mail. Previously I have used Windows Live Mail and earlier Outlook Express, both seemingly subsets of Outlook. In both of those programs when I exported the contents of an e-mail folder all the e-mails were saved as individual files which was very handy if I needed to look up a specific saved e-mail and could just double click on the file to open it. So I would like to do the same thing in Outlook as was available in both Outlook Express and Windows Live Mail. Does anyone know if this is possible? Thanks, Gerry |
#2
|
||||
|
||||
![]()
When reading an e-mail message in Outlook, you can indeed save it as an individual file. The default is MSG format, but you will need Outlook to open that format in order to view it. You could save as MHTML format which will open in Internet Explorer (which everyone using a PC should have) or in Word.
It is relatively straightforward to save a folder full of messages as msg format. Naming the files from the messages so that they are identifiable, unique and do not contain illegal filename characters is where the job gets a little more complicated. Download, extract from the zip and import frmProgress from my web site http://www.gmayor.com/Forum/frmProgress.zip into the Outlook VBA editor (File > Import File) Then copy the following to a new module. Run ProcessFolder and follow the on-screen prompts. Code:
Option Explicit Sub ProcessFolder() 'An Outlook macro by Graham Mayor - www.gmayor.com Dim olNS As Outlook.NameSpace Dim olMailFolder As Outlook.MAPIFolder Dim olItems As Outlook.Items Dim olMailItem As Outlook.MailItem Dim i As Long Dim sPath As String Dim ofrm As New frmProgress Dim PortionDone As Double On Error GoTo err_Handler Set olNS = GetNamespace("MAPI") Set olMailFolder = olNS.PickFolder sPath = InputBox("Enter the path to save the messages." & vbCr & _ "The path will be created if it doesn't exist.", _ "Save Message", "C:\Path\") Do Until Right(sPath, 1) = Chr(92) sPath = sPath & Chr(92) Loop CreateFolders sPath Set olItems = olMailFolder.Items ofrm.Show vbModeless i = 0 For Each olMailItem In olItems i = i + 1 PortionDone = i / olItems.Count ofrm.Caption = "Processing " & i & " of " & olItems.Count ofrm.lblProgress.Width = ofrm.fmeProgress.Width * PortionDone SaveMessage olMailItem, sPath DoEvents Next olMailItem Unload ofrm lbl_Exit: Set ofrm = Nothing Set olNS = Nothing Set olMailFolder = Nothing Set olItems = Nothing Set olMailItem = Nothing Exit Sub err_Handler: MsgBox Err.Number & vbCr & Err.Description Err.Clear GoTo lbl_Exit End Sub Private Sub SaveMessage(olItem As MailItem, sPath As String) 'An Outlook macro by Graham Mayor - www.gmayor.com Dim fname As String fname = Format(olItem.ReceivedTime, "yyyymmdd") & Chr(32) & _ Format(olItem.ReceivedTime, "HH.MM") & Chr(32) & olItem.SenderName & " - " & olItem.subject fname = Replace(fname, Chr(58) & Chr(41), "") fname = Replace(fname, Chr(58) & Chr(40), "") fname = Replace(fname, Chr(34), "-") fname = Replace(fname, Chr(42), "-") fname = Replace(fname, Chr(47), "-") fname = Replace(fname, Chr(58), "-") fname = Replace(fname, Chr(60), "-") fname = Replace(fname, Chr(62), "-") fname = Replace(fname, Chr(63), "-") fname = Replace(fname, Chr(124), "-") SaveUnique olItem, sPath, fname lbl_Exit: Exit Sub End Sub Private Function SaveUnique(oItem As Object, _ strPath As String, _ strFileName As String) 'An Outlook macro by Graham Mayor - www.gmayor.com Dim lngF As Long Dim lngName As Long Dim oFSO As Object Set oFSO = CreateObject("Scripting.FileSystemObject") lngF = 1 lngName = Len(strFileName) Do While oFSO.FileExists(strPath & strFileName & ".msg") = True strFileName = Left(strFileName, lngName) & "(" & lngF & ")" lngF = lngF + 1 Loop oItem.SaveAs strPath & strFileName & ".msg" lbl_Exit: Set oFSO = Nothing Exit Function End Function Private Function CreateFolders(strPath As String) 'An Office macro by Graham Mayor - www.gmayor.com Dim strTempPath As String Dim lngPath As Long Dim vPath As Variant Dim oFSO As Object Set oFSO = CreateObject("Scripting.FileSystemObject") vPath = Split(strPath, "\") strPath = vPath(0) & "\" For lngPath = 1 To UBound(vPath) strPath = strPath & vPath(lngPath) & "\" If Not oFSO.FolderExists(strPath) Then MkDir strPath Next lngPath lbl_Exit: Set oFSO = Nothing Exit Function End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
![]() Quote:
Thanks very much for the detailed info! I used to work on a database project in Access VBA so while I'm a little rusty I'm pretty sure I can get your code into Outlook. But I found VERY INTERESTING the complicated process to get the needed certificate validated in order for the VBA code to run. How on earth did you find this all out? I don't have time right now to give it all a try but I will soon and I'll let you know how it works out. Thanks again, Gerry |
#4
|
||||
|
||||
![]()
The complicated process was necessitated because creating a certificate using SelfCert.exeputs the certificate in the wrong place and so the application doesn't see it. This is no doubt due to tighter security imposed by Windows 10, as it was not ever thus.
The way to address this was found by research and the web page made as other explanations were even more tortuous to follow.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#5
|
|||
|
|||
![]()
Hi gmayor,
Well, I finally got around to giving it a try and it works!!! Boy, my VBA skills are VERY RUSTY. Initially I couldn't even get the VBA editor to appear but finally figured it out. Then I imported the form and I thought the code would come with it but then realized I had to copy and paste it from your post into a new module. I did take a look at the Macro security level but did not make any changes and it was set to: Notifications for digitally signed macros, all other macros disabled. I went ahead and ran it and aimed it at a mail folder but nothing happened. Then I realized that folder was the overall e-mail folder but there were no e-mails in that folder only other folders. So I tried it again but selected a folder with e-mails and sure enough a progress bar came up counting the number of e-mails being saved. Once done I looked at the target save folder and there were all the individual e-mails with their file name having the date, time and subject. NEAT!!!! THANKS. Then I figured out how to save it and how to set up the macro on the main HOME ribbon so its easy to access. One more request, but ONLY if its a simple change! Is there a way to aim the macro at the main e-mail folder, i.e. xxx@gmail.com and then have it find the folders under that main folder and then save all the e-mails in the each of the folders within a directory folder under the main folder. For example if I had under that gmail folder two folders named Save and Travel and the target save folder was Mail-backup. Then two directory folders would be created under Mail-backup named Save and Travel and the e-mails under the respective e-mail folders would be saved in the directory folders. This is essentially how Win Live Mail and the old Outlook Express saved batches of e-mails. AGAIN, I appreciate your work and the macro as now is very good and I'll be using it all the time. Thanks again, Gerry |
#6
|
||||
|
||||
![]()
You can certainly process all the folders under your default inbox, which I think is what you are asking. It needs a further macro to process the folders (which becomes the main macro) and some modifications to the ProcessFolder macro (see below) to take the input from the new macro (the other functions are still required).
You will notice I have added some commented out lines in the ProcessFolder sub. If restored, these lines add a category to each processed message, so that next time the process is run, the process checks for the added category and if present, the categorised messages will not be processed again. Code:
Option Explicit Sub SaveMessages() 'Graham Mayor - http://www.gmayor.com Dim cFolders As Collection Dim olFolder As Outlook.Folder Dim subFolder As Outlook.Folder Dim olNS As Outlook.NameSpace Dim strPath As String Dim sSubPath As String Dim sStore As String strPath = InputBox("Enter the path to save the messages." & vbCr & _ "The path will be created if it doesn't exist.", _ "Save Message", "C:\Outlook Message Backup\") Do Until Right(strPath, 1) = Chr(92) strPath = strPath & Chr(92) Loop Set cFolders = New Collection Set olNS = GetNamespace("MAPI") cFolders.Add olNS.GetDefaultFolder(olFolderInbox) Do While cFolders.Count > 0 Set olFolder = cFolders(1) cFolders.Remove 1 sStore = olFolder.Store sSubPath = Replace(olFolder.FolderPath, "\\" & sStore & "\", strPath) CreateFolders sSubPath ProcessFolder olFolder, sSubPath If olFolder.folders.Count > 0 Then For Each subFolder In olFolder.folders cFolders.Add subFolder Next subFolder End If Loop lbl_Exit: Set olFolder = Nothing Set subFolder = Nothing Exit Sub End Sub Private Sub ProcessFolder(olMailFolder As Outlook.Folder, sPath As String) 'Graham Mayor - http://www.gmayor.com Dim olItems As Outlook.Items Dim olMailItem As Outlook.MailItem Dim i As Long Dim ofrm As New frmProgress Dim PortionDone As Double On Error GoTo err_Handler Set olItems = olMailFolder.Items ofrm.Show vbModeless i = 0 For Each olMailItem In olItems i = i + 1 'If Not olMailItem.categories = "Backed-up To File" Then PortionDone = i / olItems.Count ofrm.Caption = olMailFolder.Name & " - Processing " & i & " of " & olItems.Count ofrm.lblProgress.Width = ofrm.fmeProgress.Width * PortionDone SaveMessage olMailItem, sPath 'olMailItem.categories = "Backed-up To File" 'olMailItem.Save DoEvents 'End If Next olMailItem Unload ofrm lbl_Exit: Set ofrm = Nothing Set olItems = Nothing Set olMailItem = Nothing Exit Sub err_Handler: MsgBox Err.Number & vbCr & Err.Description Err.Clear GoTo lbl_Exit End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#7
|
|||
|
|||
![]() Quote:
WOW! Thanks that's exactly what I want to do. I'm going out soon so I can't try it today, but I saved your new VBA code and will give it a try soon and let you know how it turns out. I assume I should just delete the current macro and then import the new code which will create the new overall macro along with the revised one. THANKS AGAIN! Gerry |
#8
|
||||
|
||||
![]()
Just replace the original ProcessFolder macro (from Sub ProcessFolder() to EndSub inclusive) with the two macros from my earlier message. The userform you imported remains as do the various functions associated with the process.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#9
|
|||
|
|||
![]() Quote:
I know its been a while since you sent me the new code but I just haven't had a chance to give it a try until now. But I have another question as I think I want to keep the original macro and then install the new code as a second macro. So I went to try the original macro and I get a popup saying that macros are disabled and look in the documentation to enable macros. Now I know the original macro did run as I successfully used it at least once to save a single folder of e-mails and it worked perfectly. I thought it probably needed that trusted certificate process you talked about, but just as a test I went into Outlook (OL)'s Trust Center and told it to allow all macros but it still wouldn't let it run. Is that correct that it needs this trusted certificate no matter what? And if so why did the macro run when I first set it up but not now? So I started to look at making the trusted certificate, but before I tried it I wanted to see where in OL's VBA system you would use to sign the macro with the certificate but I could not find it. So my question is why couldn't I run the macro when I told the Trust Center to allow all macros. And if I can create the trusted certificate how do I sign the macro with it? THANKS AGAIN for all your help! Gerry |
#10
|
||||
|
||||
![]()
When you create the certificate using the process at the link I posted earlier - http://www.gmayor.com/create_and_emp...gital_cert.htm you can add it to the Outlook Project from the Outlook VBA editor > Tools > Digital Signature. You will then be able to run the macros in the project.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#11
|
|||
|
|||
![]() Quote:
Thanks for the info. I did look in Tools before and totally missed the Digital Sig option! I'll let you know how things work out. But a curiosity question if you don't mind. Is it correct that now the original macro won't work because its not signed even though it worked when I first entered it. If it needs to be signed to work then why did it work at all when I first entered it? Also does it then mean that if a OL user writes a simple macro using a few lines of code then he has to go through the confusing process to create a signed certificate and assign the macro code to it to get it to run. I realize this is to prevent bad macros from running but it seems to put a large burden on a casual user who just wants to automate a procedure that he may use often. Thanks again, Gerry |
#12
|
||||
|
||||
![]()
I don't know the answer. I don't work for nor speak for Microsoft. Certainly you can create and run macros in Outlook, but experience suggests that if you want to run them again, after closing and re-opening Outlook, you will need to digitally sign them, and as that has recently become even more problematical due to the way that Windows stores the certificates, I prepared the web page to help users who want to create and keep Outlook macros.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#13
|
|||
|
|||
![]()
Hi gmayor,
Well, I have to give credit where credit is due!! How on earth were you able to research this certificate stuff and come up with a process to create a certificate then export it from a personal location and then import it to a trusted location. AND IT WORKED!!! I followed the steps as laid out and each step worked exactly as you indicated. Then I signed the original macro with the new trusted certificate and . . . it didn't work!! I tried it a few times and still got that "macro disabled" message. I stopped OL and restarted it and it still didn't work. I was just about to post another message to you but tried it again by stopping and restarting OL, but this time I was asked if some things (modules or programs, I forget) should be trusted. They were all from MS and I think one of the locations was where the selfcert.exe came from. So I said they were trusted. I even got a similar message from Norton (I have Norton Security on my PC) and said that should be trusted. Then I tried the macro and it worked!!! I stopped OL and started it again and no longer was asked about the trusted stuff and the macro still works! Do you know why I wasn't asked about the trust stuff the first time I stopped OL and then restarted it. It took about 3 stops and starts for it to ask me about the trust stuff. I didn't try the new version of the macro and will try that later. But at least the original macro now works when needed. I still can't get over how complicated MS made it for some one who might casually want to come up with a simple macro. I guarantee a normal user who might have some knowledge of VBA would have NO IDEA what to do with these certificates. So thanks again for all your help!!! Gerry |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Michel777 | Outlook | 2 | 01-11-2015 07:54 AM |
Saving sent mails to specific folder | kammil121 | Outlook | 0 | 10-22-2014 02:26 AM |
Saving a contact group received from someone else | kcmihrguy | Outlook | 0 | 08-20-2014 06:20 AM |
Saving senders email to contact group | RicWCO | Outlook | 0 | 03-26-2012 10:03 PM |
![]() |
taher | Outlook | 1 | 11-07-2011 11:03 PM |