+ Reply to Thread
Results 1 to 6 of 6

Thread: Save Sent Message To....

  1. #1
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Save Sent Message To....

    I'm using a standard little Excel macro to send an individual email to each person in a list:

    With ActiveSheet
        Msg = "All," & Chr(10) & Chr(10) & "As part of normal support and maintenance, this week we updated your store to v" & .[X1] & Chr(10) & Chr(10) & "Any questions please contact me directly."
        Set Emails = .Range("T2", .Range("T" & .Rows.Count).End(xlUp)).SpecialCells(xlFormulas, 2)
        
        For Each Email In Emails
            Set OutApp = CreateObject("Outlook.Application")
            Set OutMail = OutApp.CreateItem(0)
    
            Subject = Email.Offset(, -19) & " - System Update"
            With OutMail
                .To = Email.Text
                .CC = ""
                .BCC = ""
                .Subject = Subject
                .Body = Msg & Chr(10) & Chr(10) & Signature
                '.Display   'or use .Send
                .Send
            End With
            Email.Offset(, -1) = "Done"
        Next Email
    End With

    Problem, I'd like to set the "Save Sent Message To:" option on each of these emails, too, to file this email into a specific archival folder in Outlook. Is there a way to do this in Excel VBA? I could just copy all these emails manually out of the SENT EMAILS folder, but if it's possible to file them using the macro, even better.


    Bonus question: Is there any way to add an existing Signature in Outlook to these emails? I have a default signature that occurs automatically on all NEW emails I create in Outlook, but this VBA method of creating an email does not get that default signature, seems to skip that. In the code above I'm using another signature I created for the macro, but it's not the cool formatted signature I have usually in Outlook.




    (also posted here with no response so far...)
    Last edited by JBeaucaire; 07-03-2011 at 10:36 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Save Sent Message To....

    I think the answer to both is the same - create a template with the signature and save options that you want and save it to a folder, then use OutApp.CreateItemFromTemplate to create the messages.

  3. #3
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Save Sent Message To....

    I wouldn't create a new outlook instance for each email:

    With ActiveSheet
     with createobject("outlook.application")
    
      For Each Email In .columns(20).SpecialCells(xlFormulas, 2).offset(1).SpecialCells(xlFormulas, 2)
       with .CreateItem(0)
        .To = Email.Text
        .Subject = Email.Offset(, -19) & " - System Update"
        .Body = replace("All,~~As part of normal support and maintenance, this week we updated your store to v" & .[X1] & "~~Any questions please contact me directly.","~",chr(10))
        .Send
       End With
       Email.Offset(, -1) = "Done"
      next
    
      With .getnamespace("MAPI").getdefaultfolder(4)
       For Each it In .items
        it.Copy
        it.Move .folders("archive")
       Next
      end with
    
     End With
    End sub
    In this example I made a subfolder of PostOUT, name "archive".
    Outlook has a curious way of 'copying' an item: first 'copy', then 'move'

    For he signature I second RO's suggestion to use an outlook template.
    Last edited by snb; 07-01-2011 at 07:27 AM.



  4. #4
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Save Sent Message To....

    Well there you go! Always something new to learn. The CreateItemFromTemplate resolved it all, perfect! The finished code also incorporates SNB's suggestion to move the App to a single instance:
    Option Explicit
    
    Sub EmailUpdates()
    Dim OutApp  As Object
    Dim OutMail As Object
    Dim Emails  As Range
    Dim Email   As Range
    Dim Subject As String
    
    If MsgBox("Process the Activesheet?", vbYesNo, "Proceed?") = vbNo Then Exit Sub
    
    With ActiveSheet
        Set Emails = .Range("T2", .Range("T" & .Rows.Count).End(xlUp)).SpecialCells(xlFormulas, 2)
        Set OutApp = CreateObject("Outlook.Application")
        
        For Each Email In Emails
            Set OutMail = OutApp.CreateItemFromTemplate("C:\Documents and Settings\Jerry\Application Data\Microsoft\Templates\Monetra Upgrade Completed - VP2.oft")
            Subject = Email.Offset(, -19) & " - Monetra Updated"
            With OutMail
                .To = Email.Text
                .Subject = Subject
                .Display
                '.Send
            End With
            Email.Offset(, -1) = "Done"
        Next Email
    End With
    
    End Sub


    Now, if I could just get around the popup warning in Outlook for each of these emails trying to send themselves, I'd be in Nirvana. Everything I find on the internet is just too convoluted. Easier to just to press YES for each of the emails, for now.

    Thanks guys.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  5. #5
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Save Sent Message To....

    Unless you prefer to dive into the registry and it's outlook security settings you can install ClickYes.exe, that is to be downloaded here:
    http://www.contextmagic.com/downloads.htm

    Besides: your code doesn't do anything on 'archiving' (one of your questions ? see this thread's title). See my previous, amended suggestion.
    Last edited by snb; 07-01-2011 at 02:27 PM.



  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,226

    Re: Save Sent Message To....

    The TEMPLATE I'm using already has the "Save Sent Messages To:" folder selected properly. Every time I use the macro in that incarnation above the emails file themselves away properly. Thank again, all.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0