Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    May 2015
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Saving Emails to MSG using code

    Hi,

    I found the code on the post http://windowssecrets.com/forums/sho...ils+.msg+macro to do almost exactly as I want. However, I would like the ability to add the email senders name (not their email address into the filename of the saved message. Can anyone suggest how this is done.

    Thanks
    Alan

  2. #2
    New Lounger
    Join Date
    May 2015
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I solved it by adding the following code:

    Dim strMsgFrom As String
    strMsgFrom = msgItem.SenderName

    and changing the line of code that formats the filename to:

    strMsgSubj = Format(msgItem.SentOn, "yyyy-mm-dd Hh.Nn.Ss") & " " & "[From " & strMsgFrom & "]" & " " & strMsgSubj & ".msg"

  3. #3
    New Lounger
    Join Date
    May 2015
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    A further proble I have is that when the BrowseforFolder is used and you press the cancel button you get a runtime 91 error. I'm assuming I need to add some error trapping but don't know how to. The code I'm using is:

    strPath = CreateObject("Shell.Application").BrowseForFolder( 0, "Where do you want to save your incoming email?", 0, 17).Items.Item.Path

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,203
    Thanks
    49
    Thanked 989 Times in 919 Posts
    You'd need an "on error goto" statement. Using "on error resume next" makes the code skip the problematic line, then you can test if anything was returned on the next line.
    e.g.
    On Error Resume Next
    strPath = CreateObject("Shell.Application").BrowseForFolder( 0, "Where do you want to save your incoming email?", 0, 17).Items.Item.Path
    On Error Goto 0 'turn off error handling so we catch the next problem.
    if strPath = "" Then 'do whatever you need to do to get a correct response

    cheers, Paul

  5. The Following User Says Thank You to Paul T For This Useful Post:

    scoobydoo74 (2015-05-16)

  6. #5
    New Lounger
    Join Date
    May 2015
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Perfect thanks Paul. Works a treat.

    Thanks, Alan

Posting Permissions

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