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?
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