• DİKKAT

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

Değişken verileri mail ile göndermek

Katılım
30 Ağustos 2013
Mesajlar
67
Excel Vers. ve Dili
office 2016 tr
Merhaba,
Ekteki gibi bir tablom var. Her gün pivot ile hazırlıyorum bu yüzden içerikler her gün değişecek.
İstediğim şey sayfa1'de B sütununda yer alan cari kodlarının karşısındaki verileri(Ürün adını, toplam miktarı, toplam tutarı), sayfa2'deki ilgili cari kodunun karşısındaki mail adresine göndermesi.

örneğin; 2118 carisi için aaa@hotmail.com adresine, 111,222,333 ürün adlarını ve kaç adet olduğunu toplam tutarını vs göndermeli.
bugün 2118'in karşısında 3 kalem ürün var fakat yarın 25 kalem de olabilir.
Tabloyu pivot ile oluşturduğumdan hep bu formatta olacak.
Nasıl yapabiliriz acaba yardımcı olabilir misiniz?
Çok teşekkürler şimdiden
 

Ekli dosyalar

Aşağıdaki şekilde deneyiniz.


Kod:
Dim OutApp As Object, OutMail As Object
Dim baslikalan As Range
Dim son As Long
Dim Veri As Range
Dim alan As Range

Dim k As Range
    
Sub mail_gonder()
  Set shmail = Sheets("CariListe")
  mailsonsatir = shmail.Cells(Rows.Count, "B").End(3).Row
  
  Sheets("OzetTablo").Select
  sonsatir = Cells(Rows.Count, "B").End(3).Row
  
  Set OutApp = CreateObject("Outlook.Application")
  
  For j = 3 To sonsatir
      carikodu = Cells(j, "B").Value
      If carikodu = "" Then GoTo son
      For i = j + 1 To sonsatir
        gec = Cells(i, "B").Value
        If gec <> "" Then
          Exit For
        End If
      Next i
      sonalan = i - 1
      
      Set k = shmail.Range("A1:A" & mailsonsatir).Find(carikodu, , xlValues, xlWhole)
      satir = 0
      If k Is Nothing Then
      Else
       satir = k.Row
      End If

      If satir = 0 Then GoTo son
      mailadresi = shmail.Cells(satir, "B").Value
      If InStr(mailadresi, "@") = 0 Then
         MsgBox (mailadresi & " mail adresi formata uygun değil. Gönderilmedi.")
          GoTo son
      End If
      
      Set OutMail = OutApp.CreateItem(0)
      secim = "D2:G2,D" & j & ":G" & sonalan
      Set alan = Range(secim)
      'Set alan = Range("A1:AB3,A" & satir & ":AB" & satir)
          
      With OutMail
       .To = mailadresi
       .Cc = ""
       .Bcc = ""
       .Subject = "Sipariş Bilgileriniz."
       .Htmlbody = RangetoHTML(alan) & .Htmlbody
       '.SendUsingAccount = OutApp.Session.Accounts.Item(1)
       .Display
       .Send
     End With
     Set OutMail = Nothing
son:
 Next j
   Set OutApp = Nothing
    
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