Emailing Sheet But its not keeping the Colors of Cells

menor59

Well-known Member
Joined
Oct 3, 2008
Messages
574
Office Version
  1. 2021
Platform
  1. Windows
Hello all,

So when i run my Macro, It Attaches the Sheet to the Email, But its not keeping Colors i have in the Sheet in Question..The cells i have in the sheet have colors on it to highlight problems, but when the sheet is sent and the sheet is opened by the reciepent the colors are gone...just the value are there..

Your thoughts or comments?

Code:
Private Sub SendEmailButton_Click()
If eMailAddress.Text = "" Then
    MsgBox "You have Forgotten to add an Email Address", vbAbortRetryIgnore, "Email Address Please"
    Exit Sub
    
End If
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Outlook.Application
    Dim OutMail As Outlook.MailItem


    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With


    Set Sourcewb = ActiveWorkbook


    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook


    With Destwb
        If Val(Application.Version) < 12 Then
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            '&&&&&&&&&&&&&&&&&&&
            '   Select Case Sourcewb.FileFormat
                '   Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                '   Case 52:
                    '   If .HasVBProject Then
                        '   FileExtStr = ".xlsm": FileFormatNum = 52
                    '   Else
                        '   FileExtStr = ".xlsx": FileFormatNum = 51
                    '   End If
                '   Case 56: FileExtStr = ".xls": FileFormatNum = 56
                '   Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                '   End Select
            '&&&&&&&&&&&&&&&&&&&&
            'Send as xls
            '&&&&&&&&&&&&&&&&&&&&
          FileExtStr = ".xlsx": FileFormatNum = 51
        End If
    End With
    
    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = "Part of " & Sourcewb.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")


    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)


    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .To = Me.eMailAddress.Value
            .Subject = Me.Subject.Value
            .Body = Me.Greetings.Value & vbCrLf & Me.MessageBody.Value
            .Attachments.Add Destwb.FullName
            .Attachments.Add (Me.Attachment.Value)
            'You can add other files also like this
            '.Attachments.Add ("C:\test.txt")
            '____________________________
            .Display   'or use .Send
            '____________________________
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With


    'Delete the file you have sent
    Kill TempFilePath & TempFileName & FileExtStr


    Set OutMail = Nothing
    Set OutApp = Nothing


    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    
Call ClearButton_Click


End Sub


Private Sub ClearButton_Click()
With Me
    .RecipientName.Text = ""
    .eMailAddress.Text = ""
    .Subject.Text = ""
    .MessageBody.Text = ""
    .Attachment.Text = ""
    End With
    Call UserForm_Initialize
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I'd be tempted to create a emailable sheet on the fly, paste values, then paste formats then use that sheet to be emailed
 
Upvote 0
What format is the file being saved as?

Have you looked at the temporary file being created?

Looks like it could be a text file or an xlOpenXMLWorkbook and those formats could lose some information.

FileExtStr = ".xls": FileFormatNum = -4143

FileExtStr = ".xlsx": FileFormatNum = 51

if you want a regular workbook you might try:

FileExtStr = ".xls": FileFormatNum = 56
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,393
Members
449,081
Latest member
JAMES KECULAH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top