Excel VBA Macro: Resize Large Table Ranges After Pasting (As Image) In Email Body

  Рет қаралды 431

greggowaffles

greggowaffles

3 ай бұрын

Excel VBA Macro: Resize Large Table Ranges After Pasting (As Image) In Email Body
💥Subscribe: / @greggowaffles
Original Video: • Excel VBA Macro: Resiz...
Code:
Sub send_email_with_table_and_resize()
Dim OutApp As Object
Dim OutMail As Object
Dim table As Range
Dim pic As Picture
Dim ws As Worksheet
Dim wordDoc
Dim row_count As Long
Dim col_count As Long
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'grab table, convert to image, and cut
Set ws = ThisWorkbook.Sheets("Population Data")
'Set table = ws.Range("A1:C11")
ws.Activate
row_count = ws.Cells(Rows.Count, 1).End(xlUp).Row
col_count = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set table = ws.Range(Cells(1, 1), Cells(row_count, col_count))
table.Copy
Set pic = ws.Pictures.Paste
pic.Select
' With Selection
' .ShapeRange.LockAspectRatio = msoTrue
' '.ShapeRange.Height = 200
' .ShapeRange.Width = 500
' End With
pic.Cut
'create email message
On Error Resume Next
With OutMail
.to = "team@123.com"
.CC = ""
.BCC = ""
.Subject = "Country Population Data " & Format(Date, "mm-dd-yy")
.display
Set wordDoc = OutMail.GetInspector.WordEditor
With wordDoc.Range
.pasteandformat wdChartPicture
With wordDoc.inlineshapes(1)
.LockAspectRatio = msoTrue
'.Height = 500
.Width = 2500
End With
.insertParagraphafter
.insertParagraphafter
.InsertAfter "Thank you,"
.insertParagraphafter
.InsertAfter "Greg"
End With
.HTMLBody = "<BODY style = font-size:11pt; font-family:Arial> " & _
"Hi Team, <p> Please see table below: <p>" & .HTMLBody
End With
On Error GoTo 0
Set OutApp = Nothing
Set OutMail = Nothing
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 4
@makubexho
@makubexho 3 ай бұрын
great solution and coding in tackling the self-inflicted predicament by that poster - the intention of including such large amount of databody from Excel into the email body is beyond me - Do you not find it more appropriate and secure to store the data in an Excel file and attach it in the email for distribution? If I was the recipient of that email with a large table of content in the email body I would be like "WTH.."
@makubexho
@makubexho 3 ай бұрын
use outlook and emails for its purposes that are originally designed best for - do not stretch its application to fit some "eye-catching" stunts some people are blindly searching for
@greggowaffles
@greggowaffles 3 ай бұрын
Thanks for the feedback!! Gotta give the people what they want 😎
@Dexter101x
@Dexter101x 3 ай бұрын
Can't VBA use anything other than Outlook? I find it very limiting, since I already have an email manager
Excel VBA Macro: Delete Rows (Based on List of Values)
12:22
greggowaffles
Рет қаралды 605
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 19 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 56 МЛН
39kgのガリガリが踊る絵文字ダンス/39kg boney emoji dance#dance #ダンス #にんげんっていいな
00:16
💀Skeleton Ninja🥷【にんげんっていいなチャンネル】
Рет қаралды 8 МЛН
Iron Chin ✅ Isaih made this look too easy
00:13
Power Slap
Рет қаралды 36 МЛН
5 Excel Secrets You'll Be Embarrassed You Didn't Know
17:32
Excel Campus - Jon
Рет қаралды 126 М.
5 Things I wish I knew When I started using Excel VBA
12:45
Excel Macro Mastery
Рет қаралды 336 М.
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Excel VBA Macro: Insert PivotTable (in Email Body)
9:19
greggowaffles
Рет қаралды 599
10 Excel Formulas That Will Set You Apart (Cheat Sheet)
18:04
MyOnlineTrainingHub
Рет қаралды 229 М.
6 Excel Tools Most Users Never Think to Use (Files Included)
12:34
MyOnlineTrainingHub
Рет қаралды 144 М.
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 19 МЛН