Hi all,
I have a little code that I am trying to make it work but I am now stuck. I am obviously very new with VBA so I grabbed a few pieces of code from various places. Currently my code can create an e-mail (.Display or .Send) it can put the subject that I need, send from a specific Outlook Account and add the e-mail addresses that I want but I need it to do the following:
a. Add a signature (default signature) - it has some logos with hyperlinks in it - The problem here is after i add "Signature = ObjMail.HTMLBody" the text from body dissapears. I can only assume that when I add the HTMLbody for the signature it changes everything. If i do not add the signature this way then the signature doesn't display the logo but it shows HYPERLINK "link...." and I can't have that happening.
b. Add a table from excel (even if it's copy / paste the cells from an excel sheet and then I manually set the background colours etc). - This is didn't yet try but I didn't find anything about it...
Here is the code:
Sub Mail_To_SP()
'Working in Excel 2000-2016
Dim OutApp As Object
Dim OutMail As Outlook.MailItem, Signature As String
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Display
End With
Signature = OutMail.body
strbody = "Hello," & vbNewLine & vbNewLine & _
"text text" & vbNewLine & _
" " & vbNewLine & _
"text text text" & vbNewLine & _
" " & vbNewLine & _
"__" & vbNewLine & _
"__" & vbNewLine & _
" " & vbNewLine & _
"Thank you."
On Error Resume Next
With OutMail
.To = Range("AA1").Value
.CC = ""
.BCC = ""
.Subject = "text text " & Range("C26") & " " & "-text text " & Range("C36").Value & " " & Range("D36") & " " & Range("F36") & " " & "-" & " " & Range("S4").Value & " text " & "text " & Range("J26") & " at " & Range("H26") & ":" & Range("I26")
.body = strbody & vbNewLine & Signature = ObjMail.HTMLBody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.SendUsingAccount = OutApp.Session.Accounts.Item(3)
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I have a little code that I am trying to make it work but I am now stuck. I am obviously very new with VBA so I grabbed a few pieces of code from various places. Currently my code can create an e-mail (.Display or .Send) it can put the subject that I need, send from a specific Outlook Account and add the e-mail addresses that I want but I need it to do the following:
a. Add a signature (default signature) - it has some logos with hyperlinks in it - The problem here is after i add "Signature = ObjMail.HTMLBody" the text from body dissapears. I can only assume that when I add the HTMLbody for the signature it changes everything. If i do not add the signature this way then the signature doesn't display the logo but it shows HYPERLINK "link...." and I can't have that happening.
b. Add a table from excel (even if it's copy / paste the cells from an excel sheet and then I manually set the background colours etc). - This is didn't yet try but I didn't find anything about it...
Here is the code:
Sub Mail_To_SP()
'Working in Excel 2000-2016
Dim OutApp As Object
Dim OutMail As Outlook.MailItem, Signature As String
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.Display
End With
Signature = OutMail.body
strbody = "Hello," & vbNewLine & vbNewLine & _
"text text" & vbNewLine & _
" " & vbNewLine & _
"text text text" & vbNewLine & _
" " & vbNewLine & _
"__" & vbNewLine & _
"__" & vbNewLine & _
" " & vbNewLine & _
"Thank you."
On Error Resume Next
With OutMail
.To = Range("AA1").Value
.CC = ""
.BCC = ""
.Subject = "text text " & Range("C26") & " " & "-text text " & Range("C36").Value & " " & Range("D36") & " " & Range("F36") & " " & "-" & " " & Range("S4").Value & " text " & "text " & Range("J26") & " at " & Range("H26") & ":" & Range("I26")
.body = strbody & vbNewLine & Signature = ObjMail.HTMLBody
'You can add a file like this
'.Attachments.Add ("C:\test.txt")
.SendUsingAccount = OutApp.Session.Accounts.Item(3)
.Display 'or use .Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub