Hello, could someone please tell me how to solve this??
I'm using a code I found from Ron De Bruin's site, it sends wanted range via email. Problem is that I also need to add pictures into this range and email them also. This code works just fine but what seems to be the problem is that it won't email pictures at all. Could you help me?
I'm using a code I found from Ron De Bruin's site, it sends wanted range via email. Problem is that I also need to add pictures into this range and email them also. This code works just fine but what seems to be the problem is that it won't email pictures at all. Could you help me?
Code:
Sub Mail_Range()
'Working in 2000-2010
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
Dim Recipient As String
Dim r As Range
Set Source = Nothing
On Error Resume Next
Set Source = Range("A28:d65").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
On Error Resume Next
Set r = Application.InputBox("Valitse sähköpostiosoite listalta", Type:=8)
On Error GoTo 0
If r Is Nothing Then Exit Sub
Recipient = r.Value
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb = ActiveWorkbook
Set Dest = Workbooks.Add(xlWBATWorksheet)
Source.Copy
With Dest.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial Paste:=xlPasteValues
.Cells(1).PasteSpecial Paste:=xlPasteFormats
.Cells(1).Select
Application.CutCopyMode = False
End With
TempFilePath = Environ$("temp") & "\"
TempFileName = "Range of " & wb.Name & " " _
& Format(Now, "dd-mmm-yy")
If Val(Application.Version) < 12 Then
'You use Excel 2000-2003
FileExtStr = ".xls": FileFormatNum = -4143
Else
'You use 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
.SendMail Recipient, _
"Poikkeamaraportti"
If Err.Number = 0 Then Exit For
Next i
On Error GoTo 0
.Close SaveChanges:=False
End With
'Delete the file you have send
Kill TempFilePath & TempFileName & FileExtStr
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub