• Archive messages as .msg files (2007)

    Author
    Topic
    #451429

    My company deletes emails older than 90 days. Not a problem if we can archive them in a PST, but that is not allowed. If we want to save email messages, we have to use Save As:, and then save it as a .msg file. Very cumbersome. We can bulk move them to a folder of our choice, but it’s not as automatic as using rules and a PST file. Actually, it’s not automatic at all.

    Is there a way to set up a rule or run a macro that will automatically copy the email in the .msg format to a specified folder?

    Thanks, and I hope my question is clear.

    Viewing 1 reply thread
    Author
    Replies
    • #1111396

      Would you like this done when you clicking a button or run the macro, or automagically based on the age of the message, or on every message sent and received? Do you keep everything in your inbox, or do you have multiple subfolders under your inbox, or are your messages under other folders than your inbox?

      (I suppose it doesn’t help if I say your employers policy are unenlightened.) anigrin

      • #1111400

        We can have PST files, but they can only be on a central server and not our own hard drive. They reluctantly allowed PST files on the servers, but only temporarily. We’ve been told they can be zapped at any minute.A few weeks ago, many had theirs purged from their hard drives without notice.

        The messages I want saved are located (ironically enough) in a PST folder where they are filtered by using rules. I can change or delete rules if needed to make something work.

        Automatically upon receipt would be ideal. Running a macro is an acceptable way also.

        • #1111418

          This code should work for messages that are recieved after you install this code in the ThisOutlookSession Module, and close and restart Outlook. Substitute your own valid path in the .SaveAs line.

          Option Explicit

          Public WithEvents itmsNewMessages As Outlook.Items

          Private Sub Application_Startup()
          Set itmsNewMessages = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
          End Sub

          Private Sub Application_Quit()
          Set itmsNewMessages = Nothing
          End Sub

          Private Sub itmsNewMessages_ItemAdd(ByVal Item As Object)
          With Item
          If .Class = olMail Then
          .SaveAs “C:myfolderfolder” & Replace(Replace(Replace(.Subject, “:”, “”), “/”, “-“), “*”, “”) _
          & Format(.SentOn, “yyyy-mm-dd_Hh.Nn.Ss”) & “.msg”, olMSG
          End If
          End With
          End Sub

          It’s untested, so post back if it errors out and you can’t solve the error. The Replaces are to remove invalid file characters. The code to add the date is because if you get messages with the same subject, they will be overwritten by the more recent messages. (Unlike Excel or Word, you don’t get an error on overwriting a file with the SaveAs Method.)

          If you want somthing to run through your PST in one fell swoop, that can also be coded, but if you don’t have a lot of folders and subfolders, may as well do it manually.

          • #1111556

            The line:

            Public WithEvents itmsNewMessages As Outlook.Items

            lights up red and nothing happens. No error messages.

            • #1111570

              That usually indicates a syntax error, but I don’t have one. You placed this into the ThisOutlookSession module, not a standard module, correct?

              (I tested the code and left it running, it is working for me.)

            • #1111618

              Ahhh…I inserted a new module in the project rather than putting the code into the ThisOutlookSession module. I right-clicked on it figuring it would insert it where needed…thanks for pointing me in the right direction.

              I made that change and it’s working perfectly.

              The line:
              Set itmsNewMessages = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

              This indicates that the function is working in the Inbox, correct? Would I just change the name after “Folder” to the name of another folder to get it to work there? I don’t have a need to save every single email, but there are certain ones that go to other folders based on Rule settings. And if those rules point to a folder in a PST file, how do I designate that?

              And is it possible to have more than one folder with this function?

              We get several hundred emails per day and being able to designate different folders would be a huge timesaver.

              Thanks for your help on this. I’ll play around with this and see what I can come up with on my own.

            • #1111639

              > the function is working in the Inbox, correct?

              Yes.

              But as far as I know it is not possible to address more than one folder with this function – you have to create separate Item collections and Item_Add Events for each folder. (I haven’t seen any sample Item_Add code from Sue Mosher, Ron Slovak, or any other experts, that is capable of addressing multiple folders – it would be nice of we could.)

              You can get to default Folders easily by specifiying them with the GetDefault Folder Method. To get non-default folders you can either specify the folder tree as in post 712,389 , or loop the folders as Jefferson shows in post 713,982.

              Post back if you need more help.

            • #1136058

              Hello again.

              The code is working great and I’m not having any problems with it at all.

              I have messed around with it a bit to try some different naming conventions, but I’m stumped.

              Is it possible to include the sender and/or recipients in the file name?

              For example, the saved file could be, “Email Message_admin@yahoo.com_08-12-05_12.35.08″

              If the “@” is an invalid character I can just replace it.

              Thanks!

            • #1136060

              (Edited by JohnBF on 05-Dec-08 13:22. )

              Sure. “@” is valid in a file name. Try something like:

              .SaveAs “C:myfolderfolder” & Replace(Replace(Replace(.Subject & “_” & .SenderEmailAddress, “:”, “”), “/”, “-“), “*”, “”) & _
              & “_” & Format(.SentOn, “yyyy-mm-dd_Hh.Nn.Ss”) & “.msg”, olMSG

            • #1136074

              Thanks. Got it to work.

              How about recipients? I’ve tried the property “RecipientAddress” and it doesn’t seem to work.

              Thanks again for all the help.

            • #1136079

              The Property is just “MailItem.Recipients”, but if there are many recipients you may get a very long string, and you can get that always information from the saved MSG. (Not to mention that one the recipients is presumably you, which is kind of redundant, unless like me, you sometimes forget your name.) grin

            • #1136087

              I tried that in a couple of different areas and it lights everything up in yellow in the VB.

              I also tried .Recipients and it’s still yellow.

              I did notice that the obtaining sender info is “.SenderEmailAddress” and what I am using for recipients is “MailItem.Recipients”.

              What am I missing?

            • #1136093

              Take out “MailItem”. And please pardon me for not using code that exactly fits – MailItem is the object that Recipients applies to, so I just used it without rewriting the line of code.

        • #1111478

          Bob Archell’s technique reminds me that when you attempt to save multiple messages at once through the Outlook menu, only Text format is available, so you lose attachments. post 716,913 enables you to select either the current message, or multiple messages, and save them in .msg format, which retains the attachments.

    • #1111468

      Can’t help with the msg format but can offer another possible solution.

      I have Adobe Acrobat which creates an add-on in my Outlook 2007 app that allows archiving selected messages or folders.

      When I wish to retain incoming or outgoing mail, I move them to an appropriately named sub-folder within the Personal Folder environment. When the sub-folder contains many messages, I use the Adobe Acrobat add-on to create a PDF file containing all the messages within the folder. Once saved, I then delete the messages from the folder. The archived PDF file is easily searchable within Acrobat. I usually perform this archiving routine on a quarterly basis or when the sub folder is becoming too large.

      If you do not have Acrobat, perhaps you can search the Internet for another PDF writer that has a similar feature.

      Cheers, Bob

    Viewing 1 reply thread
    Reply To: Archive messages as .msg files (2007)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: