Option Explicit
' Chèn anh truc tiep vao mail
Sub SendMail2()
Dim OutApp As Object, OutMail As Object, objFSO As Object, oChart As Object
Dim Tu As Long, Den As Long, i As Long
Dim strPath As String, strFilePic As String
Dim dbWidth As Double, dbHeight As Double
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set objFSO = CreateObject("Scripting.FileSystemObject")
strPath = ThisWorkbook.Path
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strFilePic = strPath & "PicPayment.jpg"
With Sheets("Print")
Tu = .Range("AG2")
Den = .Range("AH2")
For i = Tu To Den Step 2
.Range("AH5") = i
If objFSO.FileExists(strFilePic) Then objFSO.DeleteFile strFilePic
.Range("A1:AB68").CopyPicture xlScreen, xlPicture
dbWidth = Round(.Range("A1:AB68").Width, 0)
dbHeight = Round(.Range("A1:AB68").Height, 0)
.Range("A1").Select
Set oChart = .Shapes.AddChart(Width:=dbWidth, Height:=dbHeight).Chart
oChart.Parent.Activate
oChart.Paste
oChart.Export Filename:=strFilePic, FilterName:="jpg"
oChart.Parent.Delete
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = Sheets("Print").Range("X10").Value
.Subject = "Phi" & ChrW(7871) & "u l" & ChrW(432) & ChrW(417) & "ng: " & Sheets("Print").Range("H2").Value
.Attachments.Add strFilePic, 1, 0
.HTMLBody = "Xin chào " & "<B>" & Sheets("Print").Range("K4") & "</B>" & _
"<BR><BR>Phòng Nhân s" & ChrW(7921) & " xin g" & ChrW(7917) & "i l" & ChrW(7841) & "i b" & ChrW(7843) & "ng chi ti" & ChrW(7871) & "t l" & ChrW(432) & ChrW(417) & "ng " & ChrW(273) & "ã tr" & ChrW(7843) & " (tính sai) và b" & ChrW(7843) & "ng chi ti" & ChrW(7871) & "t l" & ChrW(432) & ChrW(417) & "ng tính l" & ChrW(7841) & "i (tính " & ChrW(273) & "úng)." & _
"<BR><BR><B>Xin c" & ChrW(7843) & "m " & ChrW(417) & "n,</B><BR><BR>" & _
"<BR><BR><B>Phòng Nhân s" & ChrW(7921) & "!</B>" & _
"<img src=""cid:PicPayment.jpg"">"
.Display
SendKeys "({DOWN})", True
SendKeys "({DOWN})", True
SendKeys "({DOWN})", True
SendKeys "^({v})", True
.Send
End With
If objFSO.FileExists(strFilePic) Then objFSO.DeleteFile strFilePic
Set OutMail = Nothing
Set oChart = Nothing
Next i
End With
Set OutApp = Nothing
Set objFSO = Nothing
Set oChart = Nothing
End Sub