I'm using this code to send e-mail from excel;
Range A28:D65 is the range I send.
This is the code I use inserting picture to range A50:A65
I do like this;
I insert jpg-photo, it appears on range A50:D66, then I send it to my friend. Problem is; He can't see pictures, I think code doesn't include pictures at all, so is there something I need to add in codes??
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
Range A28:D65 is the range I send.
This is the code I use inserting picture to range A50:A65
Code:
Sub Insert_Picture()
Dim myPicture As Variant
Dim myCell As Range
myPicture = Application.GetOpenFilename _
("Pictures (*.gif; *.jpg; *.bmp; *.tif; *.png),*.gif; *.jpg; *.bmp; *.tif *.png", , "Select Picture to Import")
If VarType(myPicture) = vbBoolean Then
MsgBox "Kuvaa ei valittu"
Else
With ActiveSheet
Set myCell = .Range("A50:D65")
.Pictures.Insert(myPicture).Select
With myCell
Selection.Top = .Top
Selection.Left = .Left
Selection.Width = .Width
Selection.Height = .Height
Selection.Placement = xlMoveAndSize ' move and size with cells
Selection.PrintObject = True
'.Select
End With
End With
End If
Range("A50").Select
End Sub
I do like this;
I insert jpg-photo, it appears on range A50:D66, then I send it to my friend. Problem is; He can't see pictures, I think code doesn't include pictures at all, so is there something I need to add in codes??