Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Archive messages as .msg files (2007)

    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.

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    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.) <img src=/S/anigrin.gif border=0 alt=anigrin width=19 height=19>
    -John ... I float in liquid gardens
    UTC -7ąDS

  3. #3
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    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).It ems
    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.
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    5 Star Lounger
    Join Date
    Mar 2001
    Location
    Pickering, Ontario
    Posts
    642
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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
    Regards,
    Bob

  6. #6
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    The line:

    Public WithEvents itmsNewMessages As Outlook.Items

    lights up red and nothing happens. No error messages.

  7. #7
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    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.)
    -John ... I float in liquid gardens
    UTC -7ąDS

  8. #8
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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).It ems

    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.

  9. #9
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    > 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>post 712,389</post#> , or loop the folders as Jefferson shows in <post#=713,982>post 713,982</post#>.

    Post back if you need more help.
    -John ... I float in liquid gardens
    UTC -7ąDS

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    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>post 716,913</post:> enables you to select either the current message, or multiple messages, and save them in .msg format, which retains the attachments.
    -John ... I float in liquid gardens
    UTC -7ąDS

  11. #11
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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!

  12. #12
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    <P ID="edit" class=small>(Edited by JohnBF on 05-Dec-08 13:22. )</P>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
    -John ... I float in liquid gardens
    UTC -7ąDS

  13. #13
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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.

  14. #14
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: Archive messages as .msg files (2007)

    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.) <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    -John ... I float in liquid gardens
    UTC -7ąDS

  15. #15
    2 Star Lounger
    Join Date
    Oct 2001
    Location
    Not in KC anymore
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Archive messages as .msg files (2007)

    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?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •