I have working code (That I have pulled together from several different people) that will send an email when ran, If I step through the code I can see if putting my signature in the email, but when I go to the next step it will remove the signature and replace with the body text.
I have been googling for the last few hours and tried several different solutions, but still wont keep signature. I know there are items that look repeated, but I have them commented out while I am working on this in case I need that code again. Thank for any assistance.
I also removed the email addresses as I didnt figure ya need to see that .. lol.
I have been googling for the last few hours and tried several different solutions, but still wont keep signature. I know there are items that look repeated, but I have them commented out while I am working on this in case I need that code again. Thank for any assistance.
I also removed the email addresses as I didnt figure ya need to see that .. lol.
VBA Code:
Sub Email_CurrentWorkBook()
'Do not forget to change the email ID
'before running this code
Dim OlApp As Object
Dim NewMail As Object
Dim TempFilePath As String
Dim FileExt As String
Dim TempFileName As String
Dim FileFullPath As String
Dim MyWb As Workbook
Dim Signature As String
Set MyWb = ThisWorkbook
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Save your workbook in your temp folder of your system
'below code gets the full path of the temporary folder
'in your system
TempFilePath = Environ$("temp") & "\"
'Now get the extension of the file
'below line will return the extension
'of the file
FileExt = "." & LCase(Right(MyWb.Name, Len(MyWb.Name) - InStrRev(MyWb.Name, ".", , 1)))
'Now append a date and time stamp
'in your new file
TempFileName = MyWb.Name & "-" & Format(Now, "dd-mmm-yy h-mm-ss")
'Complete path of the file where it is saved
FileFullPath = TempFilePath & TempFileName & FileExt
'Now save your currect workbook at the above path
MyWb.SaveCopyAs FileFullPath
'Now open a new mail
Set OlApp = CreateObject("Outlook.Application")
Set NewMail = OlApp.CreateItem(0)
On Error Resume Next
With NewMail
.display
.To = " "
'.CC = " "
.BCC = ""
.Subject = TempFileName
.Body = "Please see the attached File " & vbNewLine & Signature ' Append signature to email body
.display
'.Body = "Attached is my project risk assessment"
.Attachments.Add FileFullPath '--- full path of the temp file where it is saved
.Send 'or use .Display to show you the email before sending it.
End With
On Error GoTo 0
'Since mail has been sent with the attachment
'Now delete the temp file from the temp folder
Kill FileFullPath
'set nothing to the objects created
Set NewMail = Nothing
Set OlApp = Nothing
'Now set the application properties back to true
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub