Signature is being removed when I run the rest of my VBA

Poppyrob

New Member
Joined
Jan 23, 2023
Messages
14
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
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.

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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Based on the code you show, your variable "Signature" will always be empty. At the beginning you declare the variable but later there is no assignment, so, at the line of code where you create the body the "Signature" will always be empty.
At which step di you 'see' the signature ?
 
Upvote 0
When I step through and get to this line. ( .To = " ")
When the email opens it has my signature, then when I step through to .Body it removes my signature and replaces it with the body of the email.
 
Upvote 0
From what you say I believe, since you're using . Display as the first function when creating the email, that what you see first is the signature automatically inserted by Outlook into the body of the email, it isn't the macro doing what you see. So when you step through .Body in the macro the original body is replaced by your new body (that at the moment doesn't contain a signature).
You need to google and search a snippet that reads your Outlook signature and assigns it to the variable "Signature" which will then be added to the new body.
 
Upvote 0

Forum statistics

Threads
1,224,811
Messages
6,181,081
Members
453,021
Latest member
Justyna P

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