Antonio Costa
New Member
- Joined
- Jan 29, 2023
- Messages
- 4
- Office Version
- 2021
- Platform
- Windows
Hi to every member's of MRExcel.com, hoping that all feel fine . I need some help to find if my vba is right :
* I need to send email's with this macro and using my signature of outlook
* Copy date/time and subject of the email send to a sheet in the same worksheet
At this moment the macro is working to send email, but not to entrer the signature or make a copy of the send.
Thank you all
* I need to send email's with this macro and using my signature of outlook
* Copy date/time and subject of the email send to a sheet in the same worksheet
VBA Code:
Sub Email()
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = Sheets("******").Range("C12:D36").SpecialCells(xlCellTypeVisible)
On Error Resume Next
With OutMail
.To = Range("C5").Value
.CC = Range("C6").Value
.BCC = Range("C7").Value
.Subject = Range("C8").Value
.HTMLBody = RangetoHTML(rng)
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "\" & Format(Now, "dd-mm-yy h-mm-ss") & ".html"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close SaveChanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
At this moment the macro is working to send email, but not to entrer the signature or make a copy of the send.
Thank you all