0

I have a macro that creates email. It adds three lines of spacing before the default signature when opening new email.
I tried various replace and trim solutions.

Relevant part of code:

Set objEmail = app_Outlook.CreateItem(olMailItem)
            
Dim signature As String
                          
strSalutation = "<html><head></head><body>" & sGreeting & " " & Sheets("Tabelle2").Cells(i, 5) & "," & "</body></html>"
            
objEmail.SentOnBehalfOfName = "address@mail.com"
            
objEmail.Display
              
objEmail.To = sEmail_Address

objEmail.Subject = sTitle
            
sSignature = Replace(objEmail.HTMLBody, Chr(13), "")
                       
objEmail.HTMLBody = strSalutation & "<p>" & sTemplate & objEmail.HTMLBody

I need this to work on anyone's laptop, so not just with my signature.

Community
  • 1
  • 1
Wizard
  • 11
  • 1
  • 5

3 Answers3

0

In the sample code above:

 trSalutation = "<html><head></head><body>" & sGreeting & " " & Sheets("Tabelle2").Cells(i, 5) & "," & "</body></html>"
 ...
 objEmail.HTMLBody = strSalutation & "<p>" & sTemplate & objEmail.HTMLBody

You add a new HTML element after closing the </html> tag.

Instead, you need to paste the salutation staring inside the <body> and </body> elements. As a result, you will get a well-formed HTML string.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
0

You can use a style to remove the margin, like this:

"<html><head><style>p{margin-top:0;margin-bottom:0;}</style></head><body>"
0

You can try this:

sSignature = Replace(objEmail.HTMLBody, "<p class=MsoNormal><o:p>&nbsp;</o:p></p>", "")