No video

Excel VBA Macro: Save Range (as Image) and Attach to Email

  Рет қаралды 425

greggowaffles

greggowaffles

4 ай бұрын

Excel VBA Macro: Save Range (as Image) and Attach to Email
💥Subscribe: / @greggowaffles
Code:
Sub save_range_then_email()
Dim table As Range
Dim myPic As String
Dim myPath As String
Dim ws As Worksheet
Dim cht As ChartObject
Dim lWidth As Long
Dim lHeight As Long
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set ws = ThisWorkbook.Sheets("S&P 500 Stocks")
Set table = ws.Range("A1:C11")
myPath = "C:\Users\greggowaffles\Documents\KZbin Videos\Test\Pictures\"
myPic = "Best Performing Stocks " & Format(Date, "mm-dd-yy") & " " & _
WorksheetFunction.RandBetween(1000, 9999) & ".jpg"
table.CopyPicture xlScreen, xlPicture
lWidth = table.Width
lHeight = table.Height
Set cht = ws.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)
cht.Activate
With cht.Chart
.Paste
.Export Filename:=myPath & myPic, filtername:="JPG"
End With
cht.Delete
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<BODY style = font-size: 16pt, font-family: Arial>" & _
"Hi Team, <p> Please see attachment.<p>" & _
"Thank you,<br>Greg"
On Error Resume Next
With OutMail
.to = "team@abc.com"
.CC = ""
.BCC = ""
.Subject = "S&P 500 Top Performing Stocks 2023"
.Display
.HTMLBody = strbody & .HTMLBody
.Attachments.Add myPath & myPic
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
#excelmacro #excelvba

Пікірлер: 5
@deepk82
@deepk82 4 ай бұрын
This is amazing. Keep doing the good work like this. Very helpful.
@greggowaffles
@greggowaffles 4 ай бұрын
Appreciate the feedback! Thank you!!
@cloudandsqlwithpython
@cloudandsqlwithpython 4 ай бұрын
Hi good work but when I am run it on pivot chart it create the chart on excel sheet instead of Range Picture showing counts etc
@greggowaffles
@greggowaffles 4 ай бұрын
thanks! i will look into that example
@greggowaffles
@greggowaffles 4 ай бұрын
Hope this helps! kzbin.info/www/bejne/l6vVk6ahidh4gbMsi=9Ps1M3r8ooCcNDmf
Excel VBA Macro: Insert PivotTable (in Email Body)
9:19
greggowaffles
Рет қаралды 598
Excel Conditional Formatting with Dates - 5 Examples
12:46
Computergaga
Рет қаралды 238 М.
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 43 МЛН
Summer shower by Secret Vlog
00:17
Secret Vlog
Рет қаралды 12 МЛН
What it feels like cleaning up after a toddler.
00:40
Daniel LaBelle
Рет қаралды 82 МЛН
10 awesome Power Query tricks you NEED to know! | Excel Off The Grid
15:44
Excel Off The Grid
Рет қаралды 34 М.
Excel VBA Macro: Delete Rows (Based on List of Values)
12:22
greggowaffles
Рет қаралды 607
6 Excel Tools Most Users Never Think to Use (Files Included)
12:34
MyOnlineTrainingHub
Рет қаралды 144 М.
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Excel VBA Macro: Send Multiple Emails (with Multiple Attachments)
12:09
10 Excel Formulas That Will Set You Apart (Cheat Sheet)
18:04
MyOnlineTrainingHub
Рет қаралды 229 М.
Excel VBA: The Magic of the Worksheet Change Event
14:24
Excel Macro Mastery
Рет қаралды 71 М.
5 Things I wish I knew When I started using Excel VBA
12:45
Excel Macro Mastery
Рет қаралды 336 М.
Excel VBA Macro: Paste Range (Table) As Image In Email Body
9:35
greggowaffles
Рет қаралды 34 М.
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 43 МЛН