PDA

View Full Version : Insert picture in sheet + send range via email



Chainz
07-27-2011, 05:10 AM
Hello,

can anyone help me with this? I wanna insert a picture at worksheet, it must be at range A50-D65, I've been searching for hours for some sort of code but I just can't find it. I want that when user selects button "add image", it will open a folder where user can select right pic. Is it possible that he can select multiple pictures??

Also, all this needs to be send via email. I've been using this code for sending emails but it won't include no pictures, dunno what's wrong but it will send wanted range but not any of pictures. Can you help me with also??

Here's the 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

Thanks in advance!! I would really appreaciate if someone could help me! I'm a rookie so I don't know much about VBA. Still learning..