+ Reply to Thread
Results 1 to 6 of 6

Macro that auto generates Email within Excel

Hybrid View

  1. #1
    Registered User
    Join Date
    03-19-2007
    Posts
    35

    Macro that auto generates Email within Excel

    I use a Macro that when run, will generate an email with the excel sheet attached. See attached example.

    My two questions are:
    - is it possible for the body of the email that is generated to have spaces within the text? So it shows more like the below:
    "Good morning,

    Please find today's forecast for Friday, May 07, 2010 attached.

    Thank you,

    FRC Treasury Team"

    - Also, the colors in the spreadsheet change automatically when the macro attaches the sheet. Why is this? Is it possible to do something so that this does not happen?

    Thank you,
    Attached Files Attached Files

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,885

    Re: Macro that auto generates Email within Excel

    For the spacing, try this:

        Msg = "Good morning,  " & Chr(10) & _
           "Please find today's forecast for Friday, May 07, 2010 attached. " & Chr(10) & _
           "Thank you," & Chr(10) & _
           "FRC Treasury Team"
    I'm not sure about the colors, but I'm guessing that the original file was created in Excel using a custom mapping for color indices, and when the new file is created is uses the default color indices. But I have not seen this before so I'm not sure.
    Last edited by 6StringJazzer; 05-26-2010 at 02:48 PM. Reason: broke up long line of code
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    02-25-2010
    Location
    Boston
    MS-Off Ver
    Excel 2007
    Posts
    174

    Re: Macro that auto generates Email within Excel

    I am almost positive there is an HTMLbody method that allows you to insert carriage returns and spaces via html.

    Edit: Try -

    .BodyFormat = olFormatHTML
    .HTMLBody = "<HTML><BODY>Enter the message text here. </BODY></HTML>"

    use <br/> to enter a new line and <p>, </p> for paragraphs.
    Last edited by DP978; 05-26-2010 at 02:58 PM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro that auto generates Email within Excel

    This will give you the format of the message body you requested:
        Msg = Chr(10) & "Good morning," & Chr(10) & Chr(10) & _
              "Please find today's forecast for Friday, May 07, 2010 attached." & Chr(10) & Chr(10) & _
              "Thank you," & Chr(10) & Chr(10) & _
              "FRC Treasury Team"


    If your attached file is changing somehow, you could convert that file to flat values, removing all the formulas and leaving it locked with the current values. Like so:
           'Create a workbook from the ActiveSheet and save it as a temporary file.
            WkbShts = Excel.Application.SheetsInNewWorkbook
              Excel.Application.SheetsInNewWorkbook = 1
              ActiveSheet.Copy
              ActiveSheet.Cells.Copy
              ActiveSheet.Range("A1").PasteSpecial xlPasteValues
              TempFile = TempPath & ActiveSheet.Name & ".xls"
              ActiveWorkbook.SaveAs TempFile
              ActiveWorkbook.Close
            Excel.Application.SheetsInNewWorkbook = WkbShts
    _________________
    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
    Registered User
    Join Date
    03-08-2012
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    13

    Re: Macro that auto generates Email within Excel

    Hey what if in a message I need it customized.
    For instance I want it to have part of the excel cells in the message.

    So if Im sending it to bob.... I can input in the macro bob.....

  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,612

    Re: Macro that auto generates Email within Excel

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

+ 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.6.0 RC 1