Excel VBA Macro: Resize Range (Table) Pasted As Image In Email Body

Excel VBA Macro: Resize Range (Table) Pasted As Image In Email Body
💥Subscribe: / @greggowaffles
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
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
table.Copy
Set pic = ws.Pictures.Paste
pic.Select
With Selection
.ShapeRange.LockAspectRatio = msoTrue
'.ShapeRange.Height = 200
'.ShapeRange.Width = 200
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
.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

Пікірлер: 33

  • @greggowaffles
    @greggowaffles3 ай бұрын

    hello! check out this video if your'e running into issues when using large ranges: kzread.info/dash/bejne/pIWEyNmhpdW_YdY.html

  • @two-onebee7030
    @two-onebee703023 күн бұрын

    This has proven very useful for a project I'm working on. Could you possibly explain how to add more than one table as separate images into the email body?

  • @kameya1104
    @kameya1104 Жыл бұрын

    Great tutorial on this email + copy image macro... thank you.

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Thanks for watching!!

  • @drewgossage8842
    @drewgossage8842 Жыл бұрын

    Great stuff as per usual!

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Appreciate you!!

  • @Kakarot_Son_Goku
    @Kakarot_Son_Goku Жыл бұрын

    Awesome, thanks for the video!

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Thanks so much for watching!!

  • @nhatanhnguyenhuu2745
    @nhatanhnguyenhuu2745 Жыл бұрын

    nice !!!!

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Thanks!!

  • @alanw6381
    @alanw6381 Жыл бұрын

    great tutorial. by the way, it seems like unable to run this when window's lock. will error debug on "Set pic = ws.Pictures.Paste" any possible workaround on that? thanks!

  • @kameya1104
    @kameya1104 Жыл бұрын

    Wondering if you can do a tutorial where you can delete certain outlook email or move outlook email to subfolder using VBA Macro... thank you.

  • @Kakarot_Son_Goku

    @Kakarot_Son_Goku

    Жыл бұрын

    Great idea.

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    I’ll look into this! Thanks for sharing this idea!!

  • @adampatterson3125
    @adampatterson3125Ай бұрын

    I keep running into issues with the Set pic = ws.Pictures.Paste line, gives me Run-time error '1004': Unable to get the Paste property of the Pictures Class. Any ideas? Thanks!

  • @78BLACKICE78
    @78BLACKICE78 Жыл бұрын

    Awsome video! I wonder if there s a posibility to use windows mail not outlook mail? Thank you.

  • @Zekesfunfunshow
    @Zekesfunfunshow10 ай бұрын

    Can you do a tutorial if I wanted to insert multiple pictures into an email with verbiage in between (hoping to reference cells for the verbiage)?

  • @3wXpertz
    @3wXpertz Жыл бұрын

    Do you have solution for dynamic range because table keep adding new rows? Appreciate your support in advance 🙏

  • @princegupta8454
    @princegupta8454Күн бұрын

    .Send is not working

  • @amalio15
    @amalio15 Жыл бұрын

    Great video helps me a lot. i did run into an issue with an important file of mine, where if my table range is too big (A1:AH37), im not able to resize it bigger than shaperange 500. is there a way around the size limiter? because there does not seem to be a Outlook problem, since im able to manualy resize as big as i want, once in the email body. if not is there a way to attach it to the email instead of the email body?

  • @HalbeEllgr

    @HalbeEllgr

    Жыл бұрын

    Same issue here, can resize within outlook but seems to hit a limit when using the .ShapeRange.Width

  • @amc_dl

    @amc_dl

    Жыл бұрын

    Still having the problem? I'm having the same problem too.

  • @oromax93

    @oromax93

    Жыл бұрын

    I had the same problem using format name but it worked as i used value. Try: .Pasteandformat Type:=13

  • @mikeguli7223

    @mikeguli7223

    8 ай бұрын

    What is the syntax you used? I'm trying '.PasteAndFormat Type:=13 wdChartPicture' but it won't let me.@@oromax93

  • @greggowaffles

    @greggowaffles

    3 ай бұрын

    apologies for the late reply, but hopefully this video can help yall out!! kzread.info/dash/bejne/pIWEyNmhpdW_YdY.html

  • @rafaelfelipe8956
    @rafaelfelipe89563 ай бұрын

    Is it posible replace a keyword in email body by the image?

  • @ALMNDPLAYS
    @ALMNDPLAYS Жыл бұрын

    how can i call my default signature in outlook instead of creating it thru an html body?

  • @nullhas
    @nullhas Жыл бұрын

    I Greg. Thank you. How we can add cell values in outlook mail body instead of pasting it as a picture? Please

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    Here you go! Excel VBA Macro: Send Email With Table In Body (Dynamic Range) kzread.info/dash/bejne/ha6jqa2wnavOfs4.html

  • @nullhas

    @nullhas

    Жыл бұрын

    @@greggowaffles Thank You

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    No problem!

  • @nullhas

    @nullhas

    Жыл бұрын

    Hi Greg Thank you for your help. In your previous video where you used same table to convert as a picture, I put .send after .display in coding. I could sent the mail, but could not paste table as picture. Please help