DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
Altın Üyelik Hakkında Bilgi
Sub Test()
Dim OutlookApp As Object, OutlookMsg As Object
Dim FSO As Object
Dim BodyText1 As Object, BodyText2, BodyText3 As Object
Dim MyRange As Range
Dim TempFile1 As String, TempFile2, TempFile3 As String
Dim strHTMLBody As String, strCC As String
Dim lRow As Long, NoA As Long
Dim aRng As Range
NoA = Cells(65536, 1).End(xlUp).Row
TempFile1 = "C:\TempHTML1.htm"
TempFile2 = "C:\TempHTML2.htm"
TempFile3 = "C:\TempHTML3.htm"
Set FSO = CreateObject("Scripting.FilesystemObject")
For Each aRng In Range("A2:A" & NoA).Cells.SpecialCells(xlCellTypeVisible)
On Error Resume Next
If aRng <> Empty Then
lRow = aRng.Row
Set MyRange = ActiveSheet.Range("A" & lRow & ":AC" & lRow)
If MyRange Is Nothing Then Exit Sub
ActiveWorkbook.PublishObjects.Add _
(4, TempFile1, MyRange.Parent.Name, MyRange.Address, 0, "", "").Publish True
Set BodyText1 = FSO.OpenTextFile(TempFile1, 1)
strHTMLBody = strHTMLBody & BodyText1.ReadAll
strCC = strCC & ActiveSheet.Range("AE" & lRow) & ";" & ActiveSheet.Range("AF" & lRow) & ";"
Kill TempFile1
End If
Next
Set MyRange = ActiveSheet.Range("AH" & lRow)
ActiveWorkbook.PublishObjects.Add _
(4, TempFile2, MyRange.Parent.Name, MyRange.Address, 0, "", "").Publish True
Set MyRange = ActiveSheet.Range("A1:AC1")
ActiveWorkbook.PublishObjects.Add _
(4, TempFile3, MyRange.Parent.Name, MyRange.Address, 0, "", "").Publish True
Set BodyText2 = FSO.OpenTextFile(TempFile2, 1)
Set BodyText3 = FSO.OpenTextFile(TempFile3, 1)
strHTMLBody = BodyText2.ReadAll & BodyText3.ReadAll & strHTMLBody
strHTMLBody = Replace(strHTMLBody, "align=center", "align=left", , , vbTextCompare)
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMsg = OutlookApp.CreateItem(0)
With OutlookMsg
.HTMLBody = strHTMLBody
.Subject = ActiveSheet.Range("AG" & lRow)
.To = ActiveSheet.Range("AD" & lRow)
.CC = strCC
.Send
' .Display
End With
Kill TempFile2
Kill TempFile3
Set BodyText3 = Nothing
Set BodyText2 = Nothing
Set BodyText1 = Nothing
Set OutlookMsg = Nothing
Set OutlookApp = Nothing
Set MyRange = Nothing
Set FSO = Nothing
End Sub