-
- Destek
-
-
Özel Arama
![]() |
Sub mail_gonder()
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim I As Long
Range("A1:B12").Select
Set Source = Nothing
On Error Resume Next
'1. BURASI SAYFA KORUMAYI KALDIR VE TEKRAR KOY
ActiveSheet.Unprotect Password:="" 'ŞİFRE VARSA AYARLA
Set Source = Selection.SpecialCells(xlCellTypeVisible)
ActiveSheet.Protect
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
Exit Sub
End If
If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox " Bir hata oluştu:" & vbNewLine & vbNewLine & _
"Seçim yapmadınız, hücre aralığını seçin.", vbOKOnly, "Www.ExcelVBA.Net"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Paste '2. BURASI SEÇİLİ ALANDAKİ BUTONLARI DA KOPYALAR/YAPIŞTIRIR
.Cells(1).PasteSpecial Paste:=xlPasteAll
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now, "dd-mm-yyyy h-mm-ss")
If Val(Application.Version) < 12 Then
'Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010
FileExtStr = ".xlsx": FileFormatNum = 51
End If
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
For I = 1 To 3
'3. BURASI GÖNDERİLECEK MAİL ADRESİDİR
.SendMail "Ceryanci33@Gmail.com", _
"Günlük Faaliyet Raporu"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close savechanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Sub mail_gonder()
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim I As Long
Range("AS1:BI12").Select
Set Source = Nothing
On Error Resume Next
'1. BURASI SAYFA KORUMAYI KALDIR VE TEKRAR KOY
ActiveSheet.Unprotect Password:="2023" 'ŞİFRE VARSA AYARLA
Set Source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
Exit Sub
End If
If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox " Bir hata oluştu:" & vbNewLine & vbNewLine & _
"Seçim yapmadınız, hücre aralığını seçin.", vbOKOnly, "Www.ExcelVBA.Net"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Paste '2. BURASI SEÇİLİ ALANDAKİ BUTONLARI DA KOPYALAR/YAPIŞTIRIR
.Cells(1).PasteSpecial xlPasteValuesAndNumberFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
ActiveSheet.Protect
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now, "dd-mm-yyyy h-mm-ss")
If Val(Application.Version) < 12 Then
'Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010
FileExtStr = ".xlsx": FileFormatNum = 51
End If
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
If IsNull(Application.MailSession) Then
Application.MailLogon
End If
For I = 1 To 3
'3. BURASI GÖNDERİLECEK MAİL ADRESİDİR
.SendMail Array("Ceryanci33@Gmail.com", "Ceryanci34@Gmail.com", "Ceryanci35@Gmail.com"), _
"Günlük Faaliyet Raporu"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close savechanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
If IsNull(Application.MailSession) Then
Application.MailLogon
End If
Sub mail_gonder()
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook, ws As Worksheet
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim I As Long
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
Range("AS1:BI12").Select
Set Source = Nothing
On Error Resume Next
'1. BURASI SAYFA KORUMAYI KALDIR VE TEKRAR KOY
ws.Unprotect Password:="2023" 'ŞİFRE VARSA AYARLA
Set Source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
Exit Sub
End If
If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox " Bir hata oluştu:" & vbNewLine & vbNewLine & _
"Seçim yapmadınız, hücre aralığını seçin.", vbOKOnly, "Www.ExcelVBA.Net"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Paste '2. BURASI SEÇİLİ ALANDAKİ BUTONLARI DA KOPYALAR/YAPIŞTIRIR
.Cells(1).PasteSpecial xlPasteValuesAndNumberFormats
.Cells(1).PasteSpecial xlPasteColumnWidths '4. BURASI SÜTUN GENİŞLİKLERİNİ ORJİNALİ GİBİ KOPYALAR
.Cells(1).Select
Application.CutCopyMode = False
End With
ws.Protect
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now, "dd-mm-yyyy h-mm-ss")
If Val(Application.Version) < 12 Then
'Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010
FileExtStr = ".xlsx": FileFormatNum = 51
End If
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
On Error Resume Next
For I = 1 To 3
'3. BURASI GÖNDERİLECEK MAİL ADRESİDİR
.SendMail Array("Ceryanci33@Gmail.com", "Ceryanci34@Gmail.com", "Ceryanci35@Gmail.com"), _
"Günlük Faaliyet Raporu"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close savechanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Sub mail_gonder_Modulile()
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook, ws As Worksheet
Dim TempFilePath As String
Dim TempFileName As String
Dim strTempFile As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim I As Long
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
strTempFile = Environ$("temp") & "\" & "~tmpexport.bas"
wb.VBProject.VBComponents("Module2").Export strTempFile 'modülü dışarı al
Range("AS1:BI12").Select
Set Source = Nothing
On Error Resume Next
'1. BURASI SAYFA KORUMAYI KALDIR VE TEKRAR KOY
ws.Unprotect Password:="2023" 'ŞİFRE VARSA AYARLA
Set Source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
Exit Sub
End If
If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox " Bir hata oluştu:" & vbNewLine & vbNewLine & _
"Seçim yapmadınız, hücre aralığını seçin.", vbOKOnly, "Www.ExcelVBA.Net"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Range("AS1").Select
ActiveWindow.Zoom = 55
ActiveWindow.ScrollColumn = Selection.Column
.Paste '2. BURASI SEÇİLİ ALANDAKİ BUTONLARI DA KOPYALAR/YAPIŞTIRIR
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlPasteColumnWidths
.Range("AS1").Select
Application.CutCopyMode = False
End With
ws.Protect
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now, "dd-mm-yyyy h-mm-ss")
If Val(Application.Version) < 12 Then
'Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010
FileExtStr = ".xlsm": FileFormatNum = 52
End If
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
Workbooks(TempFileName & FileExtStr).VBProject.VBComponents.Import strTempFile 'modülü içeri al
On Error Resume Next
For I = 1 To 3
'3. BURASI GÖNDERİLECEK MAİL ADRESİDİR
.SendMail Array("Ceryanci33@Gmail.com", "Ceryanci34@Gmail.com", "Ceryanci35@Gmail.com"), _
"Günlük Faaliyet Raporu"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close savechanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
Kill strTempFile
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
Ceryanci33 yazdı:hocam aynen dediğiniz şekilde olacak. Son yazdığınız kod çalışıyor fakat butona basınca asıl çalışma kitabı da açılıyor yenisiyle birlikte. Eski doyanın yerini değiştirdiğim zaman ise kopyalama butonuna basınca ekteki gibi hata alıyorum. Büyük ihtimalle mail atılan kişide aynı hatayı alacak.
Sub mail_gonder_Modulile()
Dim Source As Range
Dim Dest As Workbook
Dim wb As Workbook, ws As Worksheet
Dim TempFilePath As String
Dim TempFileName As String
Dim strTempFile As String
Dim FileExtStr As String
Dim FileFormatNum As Long
Dim I As Long
Dim shp As Shape
Dim MacroLink As String
Dim SplitLink As Variant
Dim NewLink As String
Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
strTempFile = Environ$("temp") & "\" & "~tmpexport.bas"
wb.VBProject.VBComponents("Module2").Export strTempFile 'modülü dışarı al
Range("AS1:BI12").Select
Set Source = Nothing
On Error Resume Next
'1. BURASI SAYFA KORUMAYI KALDIR VE TEKRAR KOY
ws.Unprotect Password:="2023" 'ŞİFRE VARSA AYARLA
Set Source = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Source Is Nothing Then
MsgBox "The source is not a range or the sheet is protected, please correct and try again.", vbOKOnly
Exit Sub
End If
If ActiveWindow.SelectedSheets.Count > 1 Or _
Selection.Cells.Count = 1 Or _
Selection.Areas.Count > 1 Then
MsgBox " Bir hata oluştu:" & vbNewLine & vbNewLine & _
"Seçim yapmadınız, hücre aralığını seçin.", vbOKOnly, "Www.ExcelVBA.Net"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Range("AS1").Select
ActiveWindow.Zoom = 55
ActiveWindow.ScrollColumn = Selection.Column
.Paste '2. BURASI SEÇİLİ ALANDAKİ BUTONLARI DA KOPYALAR/YAPIŞTIRIR
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlPasteColumnWidths
.Range("AS1").Select
Application.CutCopyMode = False
End With
ws.Protect
TempFilePath = Environ$("temp") & "\"
TempFileName = wb.Name & " " & Format(Now, "dd-mm-yyyy h-mm-ss")
If Val(Application.Version) < 12 Then
'Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'Excel 2007-2010
FileExtStr = ".xlsm": FileFormatNum = 52
End If
Dest.VBProject.VBComponents.Import strTempFile 'modülü içeri al
With Dest
.SaveAs TempFilePath & TempFileName & FileExtStr, FileFormat:=FileFormatNum
For Each shp In ActiveWorkbook.Sheets(1).Shapes
shp.Select
MacroLink = shp.OnAction
If MacroLink <> "" And InStr(MacroLink, "!") <> 0 Then
SplitLink = Split(MacroLink, "!")
NewLink = SplitLink(1)
If Right(NewLink, 1) = "'" Then
NewLink = Left(NewLink, Len(NewLink) - 1)
End If
shp.OnAction = "'" & TempFileName & FileExtStr & "'!" & NewLink
End If
Next shp
.Save
On Error Resume Next
For I = 1 To 3
'3. BURASI GÖNDERİLECEK MAİL ADRESİDİR
.SendMail Array("Ceryanci33@Gmail.com", "Ceryanci34@Gmail.com", "Ceryanci35@Gmail.com"), _
"Günlük Faaliyet Raporu"
If Err.Number = 0 Then Exit For
Next I
On Error GoTo 0
.Close savechanges:=False
End With
Kill TempFilePath & TempFileName & FileExtStr
Kill strTempFile
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
MsgBox "Mail gönderildi", vbInformation
End Sub
Forum Excel ile Mail İşlemleri
Bu forumu görüntüleyenler: Kayıtlı kullanıcı yok ve 1 misafir