• 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,071
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,071
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,071
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.
 
Üst