+ Reply to Thread
Results 1 to 2 of 2

Highlight variables in an E-mail

Hybrid View

  1. #1
    Registered User
    Join Date
    01-17-2013
    Location
    Austin, TX
    MS-Off Ver
    Excel 2007
    Posts
    84

    Cool Highlight variables in an E-mail

    I'm working with the following code to send an e-mail. However, I want to highlight the variables I created. I tried dw_approved.Color = 65535 , however that and others like it haven't work.

    Thanks for the help in advance. FYI, I used references to get this e-mail to work

    Sub CreateFromTemplate()
        Dim pulled_data As Worksheet
        Set pulled_data = ThisWorkbook.Worksheets("Records")
        'click on ITF Records before mailing out to get workweek date
        
        dw_approved = Format(ThisWorkbook.Worksheets("Records").Range("AL30").Value, "$#,##0")
        dw_pending = Format(ThisWorkbook.Worksheets("Records").Range("AK30").Value, "$#,##0")
        dw_percent = Format(ThisWorkbook.Worksheets("Records").Range("AO30").Value, "0%")
        itf_approved = Format(ThisWorkbook.Worksheets("Records").Range("AR30").Value, "$#,##0")
        itf_pending = Format(ThisWorkbook.Worksheets("Records").Range("AQ30").Value, "$#,##0")
        itf_percent = Format(ThisWorkbook.Worksheets("Records").Range("AT40").Value, "0%")
        workweek_for_email = pulled_data.Range("B13").Value
        ThisWorkbook.Worksheets("Records").Range("AJ18:AT51").Copy
        
        dw_approved.Color = 65535
        
        Dim myOlApp As Outlook.Application
        Dim olEmail As Outlook.MailItem
        Set myOlApp = CreateObject("Outlook.Application")
        Dim olInsp As Outlook.Inspector
        Dim wdDoc As Word.Document
        Dim strbody As String
        Set olEmail = myOlApp.CreateItemFromTemplate("C:\Users\rbirch\AppData\Roaming\Microsoft\Templates\2015_AES_Scorecard _ww.oft")
        olEmail.Display
        
        strbody = "Hello Team," & vbTab _
          & vbCr & "Here is the scorecard and Daily Activity Tracker for workweek " & workweek_for_email & vbCr & vbCr & "Synopsis: Talk about the difference between workweek scorecards cards, big wins, small wins in DW. " _
         & vbCr & vbCr & "Extracts are located at: http://myteams/sites/embedded3/Pipeline%20DB%20For%20John%20Hodges/Pipeline%20Extracts/Forms/AllItems.aspx" _
         & vbCr & vbCr & "Design Wins Summary" & vbCr _
         & "-   Approved DW " & dw_approved & "K ( " & dw_percent & " approved to KSO goal)" & vbCr _
         & "-   Pending DW " & dw_pending & "K" & vbCr _
         & vbCr & vbCr _
         & "ITF Summary" & vbCr _
         & "-   Approved ITF " & itf_approved & "K ( " & itf_percent & " approved to KSO goal)" & vbCr _
         & "-   Pending ITF " & itf_pending & "K"
        'make a random variable for salutations using an array
    
        
    
    With olEmail
        .BodyFormat = olFormatRichText
        .Subject = "2015 AES Scorecard-ww" & workweek_for_email
        Set olInsp = .GetInspector
        Set wdDoc = olInsp.WordEditor
        .Display
        wdDoc.Range.InsertBefore strbody
        ThisWorkbook.Worksheets("Records").Activate
        Range("AJ18:AT51").Copy
        wdDoc.Range(Len(strbody), Len(strbody)).Paste
        'wk7.ActiveChart.ChartArea.Copy
    End With
    ' paste scorecard
    
    'paste charts
    
    With olEmail
        .BodyFormat = olFormatHTML
        .Attachments.Add ActiveWorkbook.FullName
    End With
    
    
    End Sub

  2. #2
    Forum Contributor Gregor y's Avatar
    Join Date
    10-24-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2010 32-Bit
    Posts
    280

    Re: Highlight variables in an E-mail

    String variables like dw_approved only hold the raw text and not the associated formatting. To get at that you'd need to work with the Range of the text within the document.

    Sub CreateFromTemplate()
        Dim pulled_data As Worksheet
        Set pulled_data = ThisWorkbook.Worksheets("Records")
        'click on ITF Records before mailing out to get workweek date
        
        dw_approved = Format(ThisWorkbook.Worksheets("Records").Range("AL30").Value, "$#,##0")
        dw_pending = Format(ThisWorkbook.Worksheets("Records").Range("AK30").Value, "$#,##0")
        dw_percent = Format(ThisWorkbook.Worksheets("Records").Range("AO30").Value, "0%")
        itf_approved = Format(ThisWorkbook.Worksheets("Records").Range("AR30").Value, "$#,##0")
        itf_pending = Format(ThisWorkbook.Worksheets("Records").Range("AQ30").Value, "$#,##0")
        itf_percent = Format(ThisWorkbook.Worksheets("Records").Range("AT40").Value, "0%")
        workweek_for_email = pulled_data.Range("B13").Value
        ThisWorkbook.Worksheets("Records").Range("AJ18:AT51").Copy
        
        'dw_approved.Color = 65535
        
        Dim myOlApp As Outlook.Application
        Dim olEmail As Outlook.MailItem
        Set myOlApp = CreateObject("Outlook.Application")
        Dim olInsp As Outlook.Inspector
        Dim wdDoc As Word.Document
        Dim strbody As String
        Set olEmail = myOlApp.CreateItemFromTemplate("C:\Users\rbirch\AppData\Roaming\Microsoft\Templates\2015_AES_Scorecard _ww.oft")
        olEmail.Display
        
        strbody = "Hello Team," & vbTab _
            & vbCr & "Here is the scorecard and Daily Activity Tracker for workweek " & workweek_for_email _
            & vbCr & vbCr & "Synopsis: Talk about the difference between workweek scorecards cards, big wins, small wins in DW. " _
            & vbCr & vbCr & "Extracts are located at: http://myteams/sites/embedded3/Pipeline%20DB%20For%20John%20Hodges/Pipeline%20Extracts/Forms/AllItems.aspx" _
            & vbCr & vbCr & "Design Wins Summary" & vbCr _
            & "-   Approved DW "
        
        dw_approved_pos = Len(strbody)
        
        strbody = strbody _
            & dw_approved & "K ( " & dw_percent & " approved to KSO goal)" & vbCr _
            & "-   Pending DW " & dw_pending & "K" & vbCr _
            & vbCr & vbCr _
            & "ITF Summary" & vbCr _
            & "-   Approved ITF " & itf_approved & "K ( " & itf_percent & " approved to KSO goal)" & vbCr _
            & "-   Pending ITF " & itf_pending & "K"
        'make a random variable for salutations using an array
    
        
    
        With olEmail
            .BodyFormat = olFormatRichText
            .Subject = "2015 AES Scorecard-ww" & workweek_for_email
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            .Display
            wdDoc.Range.InsertBefore strbody
            wdDoc.Range(dw_approved_pos, dw_approved_pos + Len(dw_approved)).Font.TextColor = 65535
            wdDoc.Range(dw_approved_pos, dw_approved_pos + Len(dw_approved)).Font.Shading.BackgroundPatternColor = 1
            'olEmail.HTMLBody = strbody & olEmail.HTMLBody
            ThisWorkbook.Worksheets("Records").Activate
            Range("AJ18:AT51").Copy
            wdDoc.Range(Len(strbody), Len(strbody)).Paste
            'wk7.ActiveChart.ChartArea.Copy
        End With
        ' paste scorecard
        
        'paste charts
        
        With olEmail
            .BodyFormat = olFormatHTML
            .Attachments.Add ActiveWorkbook.FullName
        End With
        
        
    End Sub
    Last edited by Gregor y; 08-31-2015 at 06:56 PM. Reason: remove +1 from range formulas.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Formula to highlight cell based on variables
    By Dena in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 03-04-2015, 06:14 PM
  2. [SOLVED] formula to highlight cell based on two variables
    By Dena in forum Excel General
    Replies: 5
    Last Post: 02-17-2015, 04:00 PM
  3. code to attach the draft mail in new compose mail as attachment in outlook 2010
    By priya1987 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 10-10-2012, 08:38 AM
  4. Replies: 1
    Last Post: 07-22-2012, 09:26 AM
  5. How to e-mail selected row and use e-mail address in a cell to send e-mail from excel
    By syedalamgir in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-27-2010, 02:15 AM
  6. VBA to copy, highlight cells then e-mail.
    By tmtjamie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2010, 12:58 PM
  7. Replies: 2
    Last Post: 11-25-2005, 06:50 AM

Tags for this Thread

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