Removing outlook signature in vba code

ummjay

Board Regular
Joined
Oct 1, 2010
Messages
193
Hi, I've been at this for hours, and for some reason even though my .oft does not have a signature, when I generate an outlook email from my .oft using vba, it adds my default signature to the bottom. Any ideas on how to remove this? I've tried every variation of code found online. thanks!

VBA Code:
Sub Email_Macro_InPerson()
' Working in Office 2000-2016
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim FirstNameArray As Variant
    Dim LastNameArray As Variant
    Dim EmailArray As Variant
    Dim AttachmentArray As Variant
    Dim Name As Variant
    Dim FullName As Variant
    Dim Email As Variant
    Dim Attachment As Variant
    Dim sourcefile As String
    Dim strName As String
    Dim strEmail As String
    Dim strSalesEmail As String
  Set myOlApp = CreateObject("Outlook.Application")
 'Dim msgDoc As Object 'outlook wordprocessing editor
    'start to loop
    
        
        Set wksTemp = ActiveSheet
        
        Set rng = Range("C2", Range("C" & Rows.Count).End(xlUp))

        For Each r In rng    'loop through each work effort
                 'STRING VALUES
                strName = Cells(r.Row, "A")
                strSalesEmail = Cells(r.Row, "D")
                strEmail = Cells(r.Row, "C")
        
            Set myItem = myOlApp.CreateItemFromTemplate("H:\file.oft")
            
            With myItem
            
                   
                .CC = strSalesEmail
                .BCC = "email.com"
                strbody = .HTMLBody
        
                'STRING VALUES
                strName = Cells(r.Row, "A")
                strEmail = Cells(r.Row, "C")
        
                'What to Replace
                .HTMLBody = getNewHTML(.HTMLBody, strName, 2, "XXNameXX")
                 .SentOnBehalfOfName = "email.com"
        
                    .To = r.Value
                    .Importance = 2
                    
                    .Display
                                       
                  '  Set msgDoc = myItem.GetInspector.WordEditor
       ' msgDoc.Select
        'msgDoc.Windows(1).Selection.Copy
        
        'myItem.BodyFormat = olFormatRichText
        
        'msgDoc.Range.Paste

                    
                                                           
                    '.BodyFormat = 3
                                       
            End With
            Wait
        Next r
     Set myItem = Nothing
    Set myOlApp = Nothing
    
  
    Application.DisplayAlerts = False
        Application.DisplayAlerts = True
    
    End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi @ummjay

In the next line you have the function highlighted in blue, but you didn't put the code.

Rich (BB code):
.HTMLBody = getNewHTML(.HTMLBody, strName, 2, "XXNameXX")

Copy the code of that function and paste it here.
 
Upvote 0
ahh that would help!

VBA Code:
Function getNewHTML(strHTML As String, strBodyTagReplace As String, iAddOption As Integer, Optional strBodyTag As String = vbNullString) As String
'Source: Learnings from - http://msdn.microsoft.com/en-us/library/dd492012(v=office.12).aspx
'supports adding at the beginning of the message, before the template, adding in the middle of the existing HTML, or at the end of the message
'iAddOption = 1 'beginning of email body - keys in on <body and inserts after the <body xxx declaration
'iAddOption = 2 'middle of email body (requires a search string to be added)
'iAddOptin = 3 'end of the email body - keys in on and inserts before </body>

Dim intTagStart As Integer
Dim intTagEnd As Integer

    Select Case iAddOption
        Case 1 'Insert at beginning of email body
            intTagStart = InStr(1, strHTML, "<body", vbTextCompare)
            intTagEnd = InStr(intTagStart + 5, strHTML, ">")
            strBodyTag = Mid(strHTML, intTagStart, intTagEnd - intTagStart + 1)
            getNewHTML = Replace(strHTML, strBodyTag, strBodyTagReplace)
        Case 2 'Search for key string and insert in the middle of email body
            getNewHTML = Replace(strHTML, strBodyTag, strBodyTagReplace)
        Case 3 'Append to end of email body
            getNewHTML = Replace(strHTML, "</body>", strBodyTagReplace, 1, 1, vbTextCompare)
    End Select
    
End Function
 
Upvote 0
Change this line:
VBA Code:
.HTMLBody = getNewHTML(.HTMLBody, strName, 2, "XXNameXX")

For this:
VBA Code:
.HTMLBody = Replace(strName, "XXNameXX", strName)

Comment if it works for you.
 
Upvote 0
hey, thanks for the reply. didnt work. it didnt use the .oft template, and only include an email with the to, cc, bcc, on behalf of, and Name in the body. So basically the rest of the body was missing.
 
Upvote 0
Try if the following works:

If your signature is only text.

Replace this line:
VBA Code:
.HTMLBody = getNewHTML(.HTMLBody, strName, 2, "XXNameXX")

For this:
Rich (BB code):
      strbody = Replace(.HTMLBody, "The text of my signature  (Line 1)", "")     'Here put the text of your signature
'If you have more than one line:
      strbody = Replace(strbody, "The text of my signature  (Line 2)", "")

      .HTMLBody = getNewHTML(strbody, strName, 2, "XXNameXX")

-----------------
If it doesn't work then go into outlook signature settings and delete the signature.

- Select SettingsSettings> View all Outlook settings at the top of the page.
- Select Mail >Compose and reply.
- Under Email signature, delete your signature.
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,138
Members
449,098
Latest member
Doanvanhieu

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