Excel VBA Macro: Export Selected Range as Image (Save Range as Picture)

Excel VBA Macro: Export Selected Range as Image (Save Range as Picture)
📈Open a Webull brokerage account and get up to 12 FREE stocks: a.webull.com/3xbKZC7ZoXzmhAHnrk
💥Subscribe: / @greggowaffles
Code:
Sub save_range_as_image()
Dim ws As Worksheet
Dim table As Range
Dim pic As Picture
Dim cht As ChartObject
Dim myPath As String
Dim myPic As String
Dim myWidth As Long
Dim myHeight As Long
Set ws = ThisWorkbook.Sheets("S&P 500 Stocks")
Set table = ws.Range("A1:C11")
myPath = "C:\Users\greggowaffles\Documents\KZread Videos\Test\Investing\"
myPic = "Stock Performance " & Format(Date, "mm-dd-yy") & " " & _
WorksheetFunction.RandBetween(1000, 9999) & ".png"
table.CopyPicture xlScreen, xlPicture
myWidth = table.Width
myHeight = table.Height
Set cht = ws.ChartObjects.Add(Left:=0, Top:=0, _
Width:=myWidth, Height:=myHeight)
cht.Activate
With cht.Chart
.Paste
.Export Filename:=myPath & myPic, Filtername:="png"
End With
cht.Delete
End Sub
#ExcelVBA #ExcelMacro

Пікірлер: 24

  • @BenjaminTVogt
    @BenjaminTVogt9 ай бұрын

    Thanks for the post! One modification I would suggest… Instead of “xlScreen, Format:xlPicture” I would do “Appearance:=xlScreen, Format:=xlBitmap”. The original code created an image output with a weird pivot chart on top of it for me. The modification corrected this issue.

  • @turkaykoc8587
    @turkaykoc85874 ай бұрын

    Thank you for the very good explanation.

  • @m3tallicat
    @m3tallicat4 ай бұрын

    Hey Gregg. Fantastic video. I think some of the hiccups people are encountering are from them not noticing the discrepancy between the video and the code you pasted. In the video, you show Height:= myHeight. But in the code in the description it says Height:=100. That's probably why some folks said it was stretched out for them. Easy fix, just wanted to let you know. Thanks for this amazing tutorial. Super helpful!

  • @greggowaffles

    @greggowaffles

    4 ай бұрын

    I really appreciate that! Thanks a lot!!

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

    This came in just in time for a project I was working on, exactly what I was looking for! Thank you!

  • @greggowaffles

    @greggowaffles

    Жыл бұрын

    No prob! So glad to hear that!!

  • @user-il1bi2pt3g
    @user-il1bi2pt3g5 ай бұрын

    Thanks, it solved my issue

  • @dannycheung2114
    @dannycheung21147 ай бұрын

    super

  • @suthamwintachai6559
    @suthamwintachai65593 ай бұрын

    thank you

  • @shafiqr2000
    @shafiqr20002 ай бұрын

    Great video. Many thanks

  • @greggowaffles

    @greggowaffles

    2 ай бұрын

    Thank you!

  • @AS-sk3lb
    @AS-sk3lb8 ай бұрын

    Really appreciated brother for this amazing vid.

  • @greggowaffles

    @greggowaffles

    8 ай бұрын

    😎😎

  • @jonelatendido9836

    @jonelatendido9836

    6 ай бұрын

    ​@@greggowaffles could you make fastest vba code to merge selected .pdf files in a folder?

  • @juliebinu3808
    @juliebinu38085 ай бұрын

    Hi Sir, thank you for your away some video.. this tutorial help me so much!. ca do another video, to send this picture through WhatsApp numbers

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

    Hi Greg, first off, great videos please continue to put them out the world needs more genuine people who wants to help others out. Subscribed! I need help on a project to unprotect a list of workbooks from a folder all at once using a macro. Can't seem to find any guides on that. Could you help make a guide on that? Thank you in advance! Simon

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

    Hi Nice Video 👍 Question ❓ I want the code to Auto pick file name from a Cell Value Can you please tell me how to do it. Also please update the VBA code & share it with people feedback given in comments Thanks 🙏 I've Subscribed to your Channel ❤

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

    Thank you. The exported image came out a bit stretched wide with this code. I asked chatgpt, it gave me this line: Set cht = ws.ChartObjects.Add(0, 0, myRange.Width, myRange.Height) which exported the image in the correct proportions. Why I don't know.

  • @Kn2ght
    @Kn2ght6 ай бұрын

    best tut ever, just 1 question. how can i export selected range as PDF and how can i name file based on cell value(name) ?

  • @yohanestiaras9233
    @yohanestiaras92337 ай бұрын

    Hi Greg, how about the code about save selected range with "many worksheet and many range" as picture

  • @bradosborne9299
    @bradosborne92996 ай бұрын

    This is what I am looking for but can't quite make it happen. I can see the pic get copied to my sheet and then deleted, but it's not in the folder that I set the path to. I've tried to my desktop, temp, to my OneDrive folders...

  • @bradosborne9299

    @bradosborne9299

    6 ай бұрын

    okay, works on Windows, but I can't get it to complete on MacOS .Export fileName:=myPath & myPic, Filtername:="png" [This line brings up a permissions denied error]. I switched myPath to match my MacOS folder location myPath = "/users/username/desktop/filename" I have full rights to my folder, I even created another to ensure it was not on the iCloud

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

    Hi Sir, thank you for your awsome video.. this tutorial help me so much! i was looking for this tutorial. Anyway, may i know your social media or your email? i have a lil bit problem script VBA, maybe you can teach me a lil bit about my problem. Thank you in advance, Sir.