• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Excelde istenilen hücreleri mail ile gönderme

hocam bu kodları nasıl eklicez benim verdiğim örneğe mail adreslerini yazıp gönder deyince öğrencilere ait not bilgilerinin gitmesini istiyorum...
 
Mail adreslerinin AC sütununda olduğunu varsaydım.
Kod:
Sub Mail_Selection_Range_Outlook_Body()
'http://msdn.microsoft.com/en-us/library/office/ff519602(v=office.11).aspx#odc_office_UseExcelObjectModeltoSendMailPart2_MailingRangeSelectionBody

' You need to use this module with the RangetoHTML subroutine.
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    Dim mailRng As Range, rng As Range
    Dim devam
    Dim OutApp As Object, OutMail As Object
    Dim adres As String
    For i = 4 To [a65536].End(3).Row
    Set mailRng = ActiveSheet.Range("c" & i & ":aB" & i)
    
    If mailRng Is Nothing Then
        MsgBox "Seçilen hücreler ""aralık"" değil veya sayfa koruması var. " & _
               vbNewLine & "Düzeltip yeniden deneyin.", vbOKOnly
        Exit Sub
    End If
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    On Error Resume Next
    With OutMail
        .To = Cells(i, "ac")
        .CC = ""
        .BCC = ""
        .Subject = ""
        .HTMLBody = "Aşağıdaki  numara ve satır no belirtilen işlemler hakkında lütfen gerekeni yapınız." & vbCrLf & vbCrLf & RangetoHTML(mailRng)
'        .Display 'email'i sadece görüntüler. gönder butonuna basarak gönderiniz.
        .Send 'email'i gönderir. ancak güvenlik uyarısı mesajı gelir. onaylayarak devam edilir.
    End With
    On Error GoTo 0
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    Next
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
    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") & ".htm"

    'Copy the range and create a new workbook to past the data in
    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

    'Publish the sheet to a htm file
    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

    'Read all data from the htm file into RangetoHTML
    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=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
 
Alt+F11 tuşlarına basın ve bir Module açın, kodları ekleyin sonra da çalıştırın.
 
AC sütununa her öğrencinin karşısına öncelikle bir mail adresi girin sonra Module içindeyken F5 tuşuna basarak kodu çalıştırın.
 
Hamitcan Hocam Kod guzel ancak 2-3 satirlarin da maile eklenmesi daha iyi olur.. Cunku bu sekilde notun hangi derse ait oldugu anlasilmamaktadir.
 
Evet haklısınız ders isimleri çıkmamış. Biraz üzerinde çalışayım.
 
Biraz oynayınca oldu.
Kod:
Sub Mail_Selection_Range_Outlook_Body2()
'http://msdn.microsoft.com/en-us/library/office/ff519602(v=office.11).aspx#odc_office_UseExcelObjectModeltoSendMailPart2_MailingRangeSelectionBody

' You need to use this module with the RangetoHTML subroutine.
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    Dim mailRng0 As Range, mailRng1 As Range, ranrng As Range
    Dim devam
    Dim OutApp As Object, OutMail As Object
    Dim adres As String
    For i = 4 To 5
    Set mailRng0 = Range("a2:ab3")
    Set mailRng1 = Range("a" & i & ":aB" & i)
    
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    On Error Resume Next
    With OutMail
        .To = cells(i,"ac")
        .CC = ""
        .BCC = ""
        .Subject = ""
        .HTMLBody = "Aşağıdaki  numara ve satır no belirtilen işlemler hakkında lütfen gerekeni yapınız." & vbCrLf & vbCrLf & RangetoHTML(mailRng0) & RangetoHTML(mailRng1)
        .Display 'email'i sadece görüntüler. gönder butonuna basarak gönderiniz.
'        .Send 'email'i gönderir. ancak güvenlik uyarısı mesajı gelir. onaylayarak devam edilir.
    End With
    On Error GoTo 0
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    Next
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
    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") & ".htm"

    'Copy the range and create a new workbook to past the data in
    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

    'Publish the sheet to a htm file
    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

    'Read all data from the htm file into RangetoHTML
    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=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
 
hocam verdiğiniz kodları ekleyemedim resimli bir anlatım varmı bakabileceğim acaba.
 
Resimli bir anlatım maalesef yok ama 6. ve 8. mesajlarımda bahsettiğim noktalara dikkat ederseniz işi çözersiniz.
 
Yardım

Hocam merhaba, öncelikle elinize sağlık,:bravo:

Belgeleri inceledim , benimde benzer bir uygulama yapmam gerekmekte.Benim listemde satırların sonunda 1 veya daha fazla mail adresi var. Ve her mail adresine ilgili olduğu satırların tümünü aynı tablo gövdesinde alt alta ( örn öğrenci 1 ve öğrenci 3 ders notları ac4 ve ac6 da yazan aynı mail adresine , aynı zamanda öğrenci 1 ve öğrenci 3 ders notları ad4 ve ad6 da 2. bir mail adresine gitmesi gerekiyor.)

Uygulana bilir mi? yani kısacası tablodaki belirli hücreler karşısındaki mail adreslerine aynı tablo bazında gitmesi gitmesini istiyorum.
 
Küçük bir dosya ekleyin ve ne istediğinizi dosya içinde tekrar anlatın(bir örnek yardımıyla)
 
hamithocam son eklediğiniz makroyu ben sayfaya ekleyip buton ekleyemedim,sizden ricam ekleyip buraya ekleyebilirmisiniz.
 
Kod:
Sub Mail_Selection_Range_Outlook_Body2()
'http://msdn.microsoft.com/en-us/library/office/ff519602(v=office.11).aspx#odc_office_UseExcelObjectModeltoSendMailPart2_MailingRangeSelectionBody

' You need to use this module with the RangetoHTML subroutine.
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    Dim mailRng0 As Range, mailRng1 As Range, ranrng As Range
    Dim devam
    Dim OutApp As Object, OutMail As Object
    Dim adres As String
    For i = 4 To [a65536].End(3).Row
    Set mailRng0 = Range("a2:ab3")
    Set mailRng1 = Range("a" & i & ":aB" & i)
    
    
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    
    On Error Resume Next
    With OutMail
        .To = Cells(i, "ac")
        .CC = ""
        .BCC = ""
        .Subject = ""
        .HTMLBody = "Aşağıdaki  numara ve satır no belirtilen işlemler hakkında lütfen gerekeni yapınız." & vbCrLf & vbCrLf & RangetoHTML(mailRng0) & RangetoHTML(mailRng1)
        .Display 'email'i sadece görüntüler. gönder butonuna basarak gönderiniz.
'        .Send 'email'i gönderir. ancak güvenlik uyarısı mesajı gelir. onaylayarak devam edilir.
    End With
    On Error GoTo 0
    
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With
    
    Set OutMail = Nothing
    Set OutApp = Nothing
    Next
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2013
    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") & ".htm"

    'Copy the range and create a new workbook to past the data in
    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

    'Publish the sheet to a htm file
    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

    'Read all data from the htm file into RangetoHTML
    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=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function
 

Ekli dosyalar

Geri
Üst