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
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.
Thank you for the very good explanation.
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
4 ай бұрын
I really appreciate that! Thanks a lot!!
This came in just in time for a project I was working on, exactly what I was looking for! Thank you!
@greggowaffles
Жыл бұрын
No prob! So glad to hear that!!
Thanks, it solved my issue
super
thank you
Great video. Many thanks
@greggowaffles
2 ай бұрын
Thank you!
Really appreciated brother for this amazing vid.
@greggowaffles
8 ай бұрын
😎😎
@jonelatendido9836
6 ай бұрын
@@greggowaffles could you make fastest vba code to merge selected .pdf files in a folder?
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
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
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 ❤
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.
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) ?
Hi Greg, how about the code about save selected range with "many worksheet and many range" as picture
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
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
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.