Multiple CopyRangeToJPG functions HELP!

MikeLittle

New Member
Joined
Feb 5, 2016
Messages
17
I have built a project to copy a range of cells and paste them as a picture into an Outlook email. The issue is that the Excel doc has 52 tables on one sheet representing each week, and I want to have a button on each table to copy that specific range and create the email.

Sub Workload_Email_WK1()
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim signature As String
Dim MakeJPG As String
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Dim strbody As String
strbody = "Happy " & Range("'Email Info'!D2") & " Everyone," & "<br>" & _
"&emsp;" & "&emsp;" & "&emsp;" & "&emsp;" & "Projected workload attached.<br>" & " " & "<br>" & _
"<br>" & "Have a great day!<br>"
MakeJPG = CopyRangeToJPG("Workload_Projection", "A1:O13")
If MakeJPG = "" Then
MsgBox "Something went wrong, we can't create the email."
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End If
On Error Resume Next
With OutlookMail
.Display
.To = Range("'Email Info'!B3")
.CC = Range("'Email Info'!B4") & ("; ") & Range("'Email Info'!B5")
.Subject = Range("'Workload_Projection'!A1") & (" Inbound Workload Projection")
.Attachments.Add MakeJPG, 1, 1
.HTMLbody = "<html><p>" & strbody & "<br>" & "</p><img src=""cid:NamePicture.jpg"" width=890 height=175></html>" & .HTMLbody
.Attachments.Add ActiveWorkbook.FullName
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
Application.SendKeys ("%s")
Sheets("Workload_Projection").Select
Range("A1:A2").Select

End Sub

Function CopyRangeToJPG(NameWorksheet As String, RangeAddress As String) As String
Dim PictureRange As Range
With ActiveWorkbook
On Error Resume Next
.Worksheets("Workload_Projection").Activate
Set PictureRange = .Worksheets("Workload_Projection").Range("A1:O13")
If PictureRange Is Nothing Then
MsgBox "Sorry, this is not a correct range."
On Error GoTo 0
Exit Function
End If
PictureRange.CopyPicture
With .Worksheets("Workload_Projection").ChartObjects.Add(PictureRange.Left, PictureRange.Top, PictureRange.Width, PictureRange.Height)
.Activate
.Chart.Paste
.Chart.Export Environ$("temp") & Application.PathSeparator & "NamePicture.jpg", "JPG"
End With
.Worksheets("Workload_Projection").ChartObjects(.Worksheets("Workload_Projection").ChartObjects.Count).Delete
End With
CopyRangeToJPG = Environ$("temp") & Application.PathSeparator & "NamePicture.jpg"
Set PictureRange = Nothing
End Function
 

Attachments

  • Workload.png
    Workload.png
    79.9 KB · Views: 39

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top