+ Reply to Thread
Results 1 to 10 of 10

Data Bars of Conditional formatting not copying over correctly into body of HTML email

Hybrid View

astha.malik1 Data Bars of Conditional... 03-17-2014, 06:31 AM
Andy Pope Re: Data Bars of Conditional... 03-17-2014, 07:03 AM
astha.malik1 Re: Data Bars of Conditional... 03-17-2014, 07:21 AM
Andy Pope Re: Data Bars of Conditional... 03-17-2014, 07:27 AM
astha.malik1 Re: Data Bars of Conditional... 03-17-2014, 07:48 AM
Andy Pope Re: Data Bars of Conditional... 03-17-2014, 07:59 AM
astha.malik1 Re: Data Bars of Conditional... 03-17-2014, 08:39 AM
Andy Pope Re: Data Bars of Conditional... 03-17-2014, 08:44 AM
astha.malik1 Re: Data Bars of Conditional... 03-17-2014, 01:46 PM
Andy Pope Re: Data Bars of Conditional... 03-18-2014, 04:39 AM
  1. #1
    Registered User
    Join Date
    03-13-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    19

    Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Hi all,

    I've spent a lot of time trying to figure this out but without any success. It's really getting me frustrated and down

    I'm using Ron de Bruins' VBA code to send an email of a range of cells that have Data Bars (Conditional Formatting) in them. But with this code all the cell contents and formats seems to be exported to Outlook but not databars.

    Can someone PLEASE help me figure this one out!?

    I'm using Excel 2010 and Outlook 2010

    Thanks everyone!

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Make sure the data bars are in cells that excel considers to be in the used range, or the range you specify to be captured.

    If you still have a problem then you need to provide example of code and workbook used.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    03-13-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Andy , am using 'ActiveSheet.UsedRange' in my code.Below is my code.I have also attached my worksheet.

    Sub Send_Click()
    
    EmailRangeInHTML "abc.xyz@cde.com", "Team Results - Month-To-Date", ActiveSheet.UsedRange
    
    End Sub
    
    Sub EmailRangeInHTML(ByVal Recipient As String, ByVal Subject As String, Optional Range_To_Send As Variant)
      
    Dim FSO As Object
      Dim HTMLcode As String
      Dim HTMLfile As Object
      Dim MyApp As Boolean
      Dim olApp As Object
      Dim Rng As Range
      Dim TempFile As String
      Dim Wks As Worksheet
    
      Const ForReading As Long = 1
      Const olMailItem = 0
      Const olFormatHTML = 2
      Const UseDefault As Long = -2
        
         On Error GoTo CleanUp
         
         If IsMissing(Range_To_Send) Then
            Set Rng = Selection
         Else
            Select Case TypeName(Range_To_Send)
              Case Is = "Range"
                  Set Rng = Range_To_Send
              Case Is = "String"
                  Set Rng = Evaluate(Range_To_Send)
              Case Else
                  MsgBox "Your Selection is Not a Valid Range."
                  GoTo CleanUp
            End Select
         End If
         
         ' Copy the worksheet to create a new workbook
           Set Wks = Rng.Parent
           Wks.Copy
         
         ' The new workbook will be saved to the user's Temp directoy
           TempFile = Environ("Temp") & "\" & Wks.Name & ".htm"
         
         ' If a file by this exists then delete it
           If Dir(TempFile) <> "" Then Kill TempFile
         
             ' Start Outlook
               Set olApp = CreateObject("Outlook.Application")
          
             ' Convert the Message worksheet into HTML
               With ActiveWorkbook.PublishObjects.Add( _
                 SourceType:=xlSourceRange, _
                 FileName:=TempFile, _
                 Sheet:=Wks.Name, _
                 Source:=Rng.Address, _
                 HtmlType:=xlHtmlStatic)
                .Publish (True)
               End With
           
             ' Read the HTML file back as a string
               Set FSO = CreateObject("Scripting.FileSystemObject")
               Set HTMLfile = FSO.OpenTextFile(TempFile, ForReading, True, UseDefault)
               
                ' Read in the entire file as a string
                  HTMLcode = HTMLfile.ReadAll
                 
               HTMLfile.Close
              
              
             ' Re-align the HTML code to the left side of the page
               HTMLcode = Replace(HTMLcode, "align=center x:publishsource=", _
                                  "align=left x:publishsource=")
                          
             ' Compose and send the email
               Set olEmail = olApp.CreateItem(olMailItem)
                 With olEmail
                   .To = Recipient
                   .Subject = Subject
                   .BodyFormat = olFormatHTML
                   .HTMLBody = HTMLcode
                   .Display
                 End With
                
       ' Exit Outlook
        ' olApp.Quit
                
    CleanUp:
       ' Did an error occur
         If Err <> 0 Then
            MsgBox "Run-time error '" & Err.Number & "':" & vbCrLf & vbCrLf & Err.Description
         End If
       
       ' Close the new workbook and don't save it
         ActiveWorkbook.Close SaveChanges:=False
      
       ' Delete the Temp File
         If Dir(TempFile) <> "" Then Kill TempFile
       
       ' Delete the Publish Object
         With ActiveWorkbook.PublishObjects
           If .Count <> 0 Then .Item(.Count).Delete
         End With
       
       
         With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
        
       ' Free memory resources
         Set olApp = Nothing
         Set olEmail = Nothing
         Set FSO = Nothing
    
    End Sub
    Attached Files Attached Files
    Last edited by astha.malik1; 03-17-2014 at 07:45 AM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    You will need to send the range as an image to include the CF databars.
    http://www.rondebruin.nl/win/s1/outlook/amail7.htm

  5. #5
    Registered User
    Join Date
    03-13-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Sorry for missing this , I am a newbie..I have made this correction.

    Andy ,In the link you have shared , the image is added as an attachment to e-mail.I want the entire cell text including the CF databars to come in e-mail body.Please help.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    You can't. The databars are not actual cell content that you can create with html.
    If you really wanted to include the cell shading as part of the table within an email then you would need to use a formula to fake the bar.

    Something like the attached.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    03-13-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Thanks Andy .How can we paste the entire used range of the worksheet as an Image in e-mail?
    I think that might also solve my problem.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email


  9. #9
    Registered User
    Join Date
    03-13-2014
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Managed to write this code , to copy and paste the cell range as image.But somehow it gives me a 'Permission Denied' error at
    ActiveSheet.ChartObjects("EXPORT").Chart.Export "C:\SavedRange.jpg" .

    Can you please help.

    Sub Export()
    
        Dim FileName As String
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
        Dim Sourcewb As Workbook
        Dim Destwb As Workbook
        Dim ToList, CcList As String
        Dim oCht As Chart
        Dim oImg As Picture
    
        ToList = Sheets("Recipients").Range("B2").Value
        CcList = Sheets("Recipients").Range("B3").Value
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        Set rng = Nothing
        Set rng = ActiveSheet.UsedRange
    
       
        'Set oCht = Charts.Add
       
        'oCht.Paste
        'oCht.Export FileName:=Environ$("temp") & "\" & "SavedRange.jpg", Filtername:="JPG"
        'oCht.Delete
        
        Set oRange = rng.SpecialCells(xlCellTypeVisible)
        oRange.CopyPicture xlScreen, xlPicture
        With ActiveSheet.ChartObjects.Add(Left:=oRange.Left, Top:=oRange.Top, _
        Width:=oRange.Width, Height:=oRange.Height)
        .Name = "EXPORT"
        .Activate
        End With
        
        ActiveChart.Paste
        ActiveSheet.ChartObjects("EXPORT").Chart.Export "C:\SavedRange.jpg"
        ActiveSheet.ChartObjects("EXPORT").Delete
        
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
        
       
        With OutMail
            .To = ToList
            .CC = CcList
            .BCC = ""
            .Subject = "Pricing - Weekly Status Update - " + Format(Now(), "mmmm dd")
            '.HTMLBody = RangetoHTML(rng)
            .HTMLBody = "<BODY><FONT face=Arial color=#000080 size=2></FONT>" & _
        "<IMG alt='' hspace=0 src='cid:SavedRange.jpg' align=baseline border=0>&nbsp;</BODY>"
           .Save
            
            .Display
            '.Send
        End With
     
    
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    Last edited by astha.malik1; 03-17-2014 at 01:58 PM.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Data Bars of Conditional formatting not copying over correctly into body of HTML email

    Why did you change the output folder location from your default temporary folder to the root directory?
    You probably don't have permission to save files to the root folder.

+ 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. Conditional formatting not copying over correctly into body of HTML email
    By seaottr in forum Excel Programming / VBA / Macros
    Replies: 29
    Last Post: 04-10-2017, 01:01 PM
  2. [SOLVED] Data Bars in Conditional Format are not displaying % from 0-100 correctly in the cell
    By maldoncn in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-21-2013, 02:17 AM
  3. Paste Conditional formatting into Outlook email body
    By tabkaz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2013, 07:58 PM
  4. Encode Text Of Body Of Email Into HTML
    By WJO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2012, 02:27 PM
  5. Excel macro to send HTML Body email
    By Benjamin2008 in forum Excel General
    Replies: 1
    Last Post: 05-01-2010, 05:29 AM

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