• DİKKAT

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

VBA ile gönderilen mail kodunda PDF düzeltmesi

Katılım
22 Eylül 2012
Mesajlar
1,072
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Merhaba,

Aşağıdaki kod ile excelin aktif sayfasının bir kopyasını ve bunun pdf formatına çevrilmiş halini mail ile gönderebilmekteyim.
PDF olmadan sadece exceli göndermek için nasıl bir düzeltme yapmak gerekir?


Kod:
'On Error Resume Next
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
   
   
    Dim isim As String
    Dim s1 As Worksheet
   
    Set s1 = ActiveSheet
    isim = Date & "-" & s1.Name
   

 
   yol = ActiveWorkbook.Path & "\" & isim
   s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=yol, Quality:=xlQualityStandard, _
             IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    ' Next, copy the sheet to a new workbook.
    ' You can also use the following line, instead of using the ActiveSheet object,
   ' if you know the name of the sheet you want to mail :
    ' Sheets("Sheet5").Copy
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    ' Determine the Excel version, and file extension and format.
    With Destwb
        If Val(Application.Version) < 12 Then
            ' For Excel 2000-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            ' For Excel 2007-2010, exit the subroutine if you answer
            ' NO in the security dialog that is displayed when you copy
            ' a sheet from an .xlsm file with macros disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "You answered NO in the security dialog."
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        'FileExtStr = ".xlsm": FileFormatNum = 52 ' 52
                        FileExtStr = ".xlsx": FileFormatNum = 51 ' 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    ' You can use the following statements to change all cells in the
   ' worksheet to values.
        'With Destwb.Sheets(1).UsedRange
            '.Cells.Copy
            '.Cells.PasteSpecial xlPasteValues
            '.Cells(1).Select
        'End With
       'Application.CutCopyMode = False

    ' Save the new workbook, mail, and then delete it.
    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim '& " " & Sourcewb.Name
           

    Set OutApp = CreateObject("Outlook.Application")
   
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
       ' Change the mail address and subject in the macro before
       ' running the procedure.
        With OutMail
            .To = "deneme@deneme.com"
            '.To = "deneme@deneme.com"
            .CC = "deneme@deneme.com"
            .BCC = ""
            .Subject = "Banka Ödeme Talimatı Listesi" & " " & isim
            .Body = "Talimat Listesi ektedir..." & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                ""

               
         
            .Attachments.Add Destwb.FullName
            .Attachments.Add yol & ".pdf"
            '.Close SaveChanges:=False  '
            ' You can add other files by uncommenting the following statement.
            '.Attachments.Add ("C:\test.txt")
            ' In place of the following statement, you can use ".Display" to
            ' display the mail.
            .Send
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

    ' Delete the file after sending.
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
   
    'UserForm5.Show
   
End Sub
 
Son düzenleme:

mustafa1205

Altın Üye
Katılım
23 Ekim 2010
Mesajlar
1,431
Excel Vers. ve Dili
Office 2016 / 64 Bit - Türkçe
Altın Üyelik Bitiş Tarihi
18-07-2026
Sub AktifSayfaExcelOlarakMailGonder()

On Error Resume Next

Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

Dim isim As String
Dim s1 As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

Set s1 = ActiveSheet
Set Sourcewb = ActiveWorkbook

isim = Format(Date, "yyyy-mm-dd") & "-" & s1.Name

' Aktif sayfayı yeni bir workbook'a kopyala
s1.Copy
Set Destwb = ActiveWorkbook

' Excel versiyonuna göre dosya formatı
If Val(Application.Version) < 12 Then
FileExtStr = ".xls"
FileFormatNum = -4143
Else
Select Case Sourcewb.FileFormat
Case 51
FileExtStr = ".xlsx": FileFormatNum = 51
Case 52
FileExtStr = ".xlsx": FileFormatNum = 51
Case 56
FileExtStr = ".xls": FileFormatNum = 56
Case Else
FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If

' Geçici klasöre kaydet
TempFilePath = Environ$("temp") & "\"
TempFileName = isim

Destwb.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum

' Outlook mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "deneme@deneme.com"
.CC = "deneme@deneme.com"
.BCC = ""
.Subject = "Banka Ödeme Talimatı Listesi " & isim
.Body = "Talimat listesi ektedir." & vbCrLf & vbCrLf & _
"İyi çalışmalar."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send ' Göndermek yerine görmek istersen .Display yaz
End With

' Temizlik
Destwb.Close SaveChanges:=False
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

Application.ScreenUpdating = True
Application.EnableEvents = True

On Error GoTo 0

End Sub



bu şekilde bir dener misiniz..
 
Katılım
22 Eylül 2012
Mesajlar
1,072
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Sub AktifSayfaExcelOlarakMailGonder()

On Error Resume Next

Dim FileExtStr As String
Dim FileFormatNum As Long
Dim Sourcewb As Workbook
Dim Destwb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim OutApp As Object
Dim OutMail As Object

Dim isim As String
Dim s1 As Worksheet

Application.ScreenUpdating = False
Application.EnableEvents = False

Set s1 = ActiveSheet
Set Sourcewb = ActiveWorkbook

isim = Format(Date, "yyyy-mm-dd") & "-" & s1.Name

' Aktif sayfayı yeni bir workbook'a kopyala
s1.Copy
Set Destwb = ActiveWorkbook

' Excel versiyonuna göre dosya formatı
If Val(Application.Version) < 12 Then
FileExtStr = ".xls"
FileFormatNum = -4143
Else
Select Case Sourcewb.FileFormat
Case 51
FileExtStr = ".xlsx": FileFormatNum = 51
Case 52
FileExtStr = ".xlsx": FileFormatNum = 51
Case 56
FileExtStr = ".xls": FileFormatNum = 56
Case Else
FileExtStr = ".xlsb": FileFormatNum = 50
End Select
End If

' Geçici klasöre kaydet
TempFilePath = Environ$("temp") & "\"
TempFileName = isim

Destwb.SaveAs TempFilePath & TempFileName & FileExtStr, _
FileFormat:=FileFormatNum

' Outlook mail
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
.To = "deneme@deneme.com"
.CC = "deneme@deneme.com"
.BCC = ""
.Subject = "Banka Ödeme Talimatı Listesi " & isim
.Body = "Talimat listesi ektedir." & vbCrLf & vbCrLf & _
"İyi çalışmalar."
.Attachments.Add TempFilePath & TempFileName & FileExtStr
.Send ' Göndermek yerine görmek istersen .Display yaz
End With

' Temizlik
Destwb.Close SaveChanges:=False
Kill TempFilePath & TempFileName & FileExtStr

Set OutMail = Nothing
Set OutApp = Nothing

Application.ScreenUpdating = True
Application.EnableEvents = True

On Error GoTo 0

End Sub



bu şekilde bir dener misiniz..
Sayın @mustafa1205 sanırım olmuş. Teşekkürler.

Sanırım dememin sebebi benim şahsi bilgisayarımdaki mail hesaplarındaki bir anlamsız sıkıntı ile ilgili. Sadece excel dosyası içeren mailler gönderebiliyorum kendime. Ancak trafikte bekleyen eski mailler geliyormuş gibi durum var. Emin olamadığım için sanırım dedim.

Teşekkürler tekrardan desteğiniz için.
 

mustafa1205

Altın Üye
Katılım
23 Ekim 2010
Mesajlar
1,431
Excel Vers. ve Dili
Office 2016 / 64 Bit - Türkçe
Altın Üyelik Bitiş Tarihi
18-07-2026
Umarım Hallolmuştur. Kolay Gelsin. İyi Çalışmalar dilerim...
 
Katılım
22 Eylül 2012
Mesajlar
1,072
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Merhaba,
mevcud kodlarınızda ki

.Attachments.Add yol & ".pdf"

satırını silerek deneyiniz.

Teşekkürler, aslında bunu denemiştim. Ancak şahsi bilgisayarımda denediğim için, mail göndermede anlamadım sıkıntı yaşadığım için emin olamamıştım.
 

muhasebeciyiz

Altın Üye
Katılım
10 Şubat 2006
Mesajlar
1,241
Excel Vers. ve Dili
Office 2016
64 Bit
Altın Üyelik Bitiş Tarihi
21-12-2027
Bunuda denermisiniz

Kod:
Sub MailAt()

    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object

    Dim isim As String
    Dim s1 As Worksheet
    Dim yol As String
    Dim pdfPath As String

    On Error GoTo HATA

    If ActiveWorkbook.Path = "" Then
        MsgBox "Dosyayı önce kaydedin (Workbook path boş)."
        Exit Sub
    End If

    Set s1 = ActiveSheet
    isim = Format(Date, "yyyy-mm-dd") & "-" & s1.Name

    yol = ActiveWorkbook.Path & "\" & isim
    pdfPath = yol & ".pdf"

    s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    Application.ScreenUpdating = False
    Application.EnableEvents = False

    Set Sourcewb = ActiveWorkbook

    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    If Val(Application.Version) < 12 Then
        FileExtStr = ".xls": FileFormatNum = -4143
    Else
        Select Case Sourcewb.FileFormat
            Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 52: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 56: FileExtStr = ".xls": FileFormatNum = 56
            Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
        End Select
    End If

    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim

    Destwb.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
        .To = "deneme@deneme.com"
        .CC = "deneme@deneme.com"
        .Subject = "Banka Ödeme Talimatı Listesi " & isim
        .Body = "Talimat Listesi ektedir..."
        .Attachments.Add Destwb.FullName
        .Attachments.Add pdfPath
        .Display
    End With

    Destwb.Close savechanges:=False

    Kill TempFilePath & TempFileName & FileExtStr

    Application.ScreenUpdating = True
    Application.EnableEvents = True

    Exit Sub

HATA:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    MsgBox "Hata: " & Err.Number & vbCrLf & Err.Description
End Sub
 
Katılım
22 Eylül 2012
Mesajlar
1,072
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
Bunuda denermisiniz

Kod:
Sub MailAt()

    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object

    Dim isim As String
    Dim s1 As Worksheet
    Dim yol As String
    Dim pdfPath As String

    On Error GoTo HATA

    If ActiveWorkbook.Path = "" Then
        MsgBox "Dosyayı önce kaydedin (Workbook path boş)."
        Exit Sub
    End If

    Set s1 = ActiveSheet
    isim = Format(Date, "yyyy-mm-dd") & "-" & s1.Name

    yol = ActiveWorkbook.Path & "\" & isim
    pdfPath = yol & ".pdf"

    s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=pdfPath, Quality:=xlQualityStandard, _
        IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    Application.ScreenUpdating = False
    Application.EnableEvents = False

    Set Sourcewb = ActiveWorkbook

    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    If Val(Application.Version) < 12 Then
        FileExtStr = ".xls": FileFormatNum = -4143
    Else
        Select Case Sourcewb.FileFormat
            Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 52: FileExtStr = ".xlsx": FileFormatNum = 51
            Case 56: FileExtStr = ".xls": FileFormatNum = 56
            Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
        End Select
    End If

    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim

    Destwb.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With OutMail
        .To = "deneme@deneme.com"
        .CC = "deneme@deneme.com"
        .Subject = "Banka Ödeme Talimatı Listesi " & isim
        .Body = "Talimat Listesi ektedir..."
        .Attachments.Add Destwb.FullName
        .Attachments.Add pdfPath
        .Display
    End With

    Destwb.Close savechanges:=False

    Kill TempFilePath & TempFileName & FileExtStr

    Application.ScreenUpdating = True
    Application.EnableEvents = True

    Exit Sub

HATA:
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    MsgBox "Hata: " & Err.Number & vbCrLf & Err.Description
End Sub
Sayın @muhasebeciyiz teşekkürler, buda alternatif güzel bir çözüm. Mail gitmeden önce yüklenmiş olarak ekranda, gönder olayını manuel yapıyoruz. Mail üzerinde değişiklik yapılabiliyor.
 

htsumer

Altın Üye
Altın Üye
Katılım
7 Eylül 2004
Mesajlar
973
Excel Vers. ve Dili
Excel-2003
Altın Üyelik Bitiş Tarihi
16.08.2026
Merhaba,

Aşağıdaki kod ile excelin aktif sayfasının bir kopyasını ve bunun pdf formatına çevrilmiş halini mail ile gönderebilmekteyim.
PDF olmadan sadece exceli göndermek için nasıl bir düzeltme yapmak gerekir?


Kod:
'On Error Resume Next
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
  
  
    Dim isim As String
    Dim s1 As Worksheet
  
    Set s1 = ActiveSheet
    isim = Date & "-" & s1.Name
  


   yol = ActiveWorkbook.Path & "\" & isim
   s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=yol, Quality:=xlQualityStandard, _
             IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    ' Next, copy the sheet to a new workbook.
    ' You can also use the following line, instead of using the ActiveSheet object,
   ' if you know the name of the sheet you want to mail :
    ' Sheets("Sheet5").Copy
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    ' Determine the Excel version, and file extension and format.
    With Destwb
        If Val(Application.Version) < 12 Then
            ' For Excel 2000-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            ' For Excel 2007-2010, exit the subroutine if you answer
            ' NO in the security dialog that is displayed when you copy
            ' a sheet from an .xlsm file with macros disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "You answered NO in the security dialog."
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        'FileExtStr = ".xlsm": FileFormatNum = 52 ' 52
                        FileExtStr = ".xlsx": FileFormatNum = 51 ' 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    ' You can use the following statements to change all cells in the
   ' worksheet to values.
        'With Destwb.Sheets(1).UsedRange
            '.Cells.Copy
            '.Cells.PasteSpecial xlPasteValues
            '.Cells(1).Select
        'End With
       'Application.CutCopyMode = False

    ' Save the new workbook, mail, and then delete it.
    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim '& " " & Sourcewb.Name
          

    Set OutApp = CreateObject("Outlook.Application")
  
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
       ' Change the mail address and subject in the macro before
       ' running the procedure.
        With OutMail
            .To = "deneme@deneme.com"
            '.To = "deneme@deneme.com"
            .CC = "deneme@deneme.com"
            .BCC = ""
            .Subject = "Banka Ödeme Talimatı Listesi" & " " & isim
            .Body = "Talimat Listesi ektedir..." & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                "" & vbCrLf & _
                ""

              
        
            .Attachments.Add Destwb.FullName
            .Attachments.Add yol & ".pdf"
            '.Close SaveChanges:=False  '
            ' You can add other files by uncommenting the following statement.
            '.Attachments.Add ("C:\test.txt")
            ' In place of the following statement, you can use ".Display" to
            ' display the mail.
            .Send
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

    ' Delete the file after sending.
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
  
    'UserForm5.Show
  
End Sub
PHP:
Sub ExcelMailGonder()
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
  
    Dim isim As String
    Dim s1 As Worksheet
  
    Set s1 = ActiveSheet
    isim = Date & "-" & s1.Name

    ' PDF satırlarını tamamen kaldırdık
    ' yol = ActiveWorkbook.Path & "\" & isim
    ' s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=yol, Quality:=xlQualityStandard, _
    '          IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    ' Aktif sayfayı kopyala
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    ' Excel formatını belirle
    With Destwb
        If Val(Application.Version) < 12 Then
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52
                    If .HasVBProject Then
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
            End Select
        End Select
    End With

    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .To = "deneme@deneme.com"
            .CC = "deneme@deneme.com"
            .BCC = ""
            .Subject = "Banka Ödeme Talimatı Listesi" & " " & isim
            .Body = "Talimat Listesi ektedir..."
          
            ' PDF eklentisini kaldırdık, sadece Excel eklenecek
            .Attachments.Add Destwb.FullName
          
            .Send
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

    ' Geçici Excel dosyasını sil
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Katılım
22 Eylül 2012
Mesajlar
1,072
Excel Vers. ve Dili
excel 2010

excel 2013
Altın Üyelik Bitiş Tarihi
06-08-2025
PHP:
Sub ExcelMailGonder()
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim OutApp As Object
    Dim OutMail As Object
 
    Dim isim As String
    Dim s1 As Worksheet
 
    Set s1 = ActiveSheet
    isim = Date & "-" & s1.Name

    ' PDF satırlarını tamamen kaldırdık
    ' yol = ActiveWorkbook.Path & "\" & isim
    ' s1.ExportAsFixedFormat Type:=xlTypePDF, Filename:=yol, Quality:=xlQualityStandard, _
    '          IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook

    ' Aktif sayfayı kopyala
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    ' Excel formatını belirle
    With Destwb
        If Val(Application.Version) < 12 Then
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52
                    If .HasVBProject Then
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
            End Select
        End Select
    End With

    TempFilePath = Environ$("temp") & "\"
    TempFileName = isim

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
        On Error Resume Next
        With OutMail
            .To = "deneme@deneme.com"
            .CC = "deneme@deneme.com"
            .BCC = ""
            .Subject = "Banka Ödeme Talimatı Listesi" & " " & isim
            .Body = "Talimat Listesi ektedir..."
         
            ' PDF eklentisini kaldırdık, sadece Excel eklenecek
            .Attachments.Add Destwb.FullName
         
            .Send
        End With
        On Error GoTo 0
        .Close savechanges:=False
    End With

    ' Geçici Excel dosyasını sil
    Kill TempFilePath & TempFileName & FileExtStr

    Set OutMail = Nothing
    Set OutApp = Nothing

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
Geç gördüm cevabınızı. Teşekkürler destek için
 

relaxim

Altın Üye
Katılım
30 Ağustos 2009
Mesajlar
589
Excel Vers. ve Dili
LTSC Pro Plus 2024 Türkçe
Altın Üyelik Bitiş Tarihi
15.06.2027
Merhabalar
Ekstre sayfasında yazdırma alanı belirlediğim kısmı (Sütunlar sabit son dolu satıra kadar, burası vba ile kod yazılı) maile ek olarak gönderebilir miyiz? Excel, pdf, word fark etmez.
Yukarıda Muhasebeyiz rumuzlu arkadaşın kodu hem pdf hem excel olarak ekledi. Excelli xlsx veya xlsm olarak kaydetmemi istiyor.
 
Üst