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

  Рет қаралды 5,838

greggowaffles

greggowaffles

Күн бұрын

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\KZbin 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

Пікірлер: 25
@BenjaminTVogt
@BenjaminTVogt 9 ай бұрын
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.
@samyboyster
@samyboyster 2 күн бұрын
Hey Greg, Amazing video, thanks a lot. I have a question. Is that possible picture save that picture on network. I have to try but than I have an error message that the path not existed
@turkaykoc8587
@turkaykoc8587 4 ай бұрын
Thank you for the very good explanation.
@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-il1bi2pt3g 5 ай бұрын
Thanks, it solved my issue
@dannycheung2114
@dannycheung2114 7 ай бұрын
super
@suthamwintachai6559
@suthamwintachai6559 3 ай бұрын
thank you
@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
@shafiqr2000
@shafiqr2000 3 ай бұрын
Great video. Many thanks
@greggowaffles
@greggowaffles 3 ай бұрын
Thank you!
@AS-sk3lb
@AS-sk3lb 8 ай бұрын
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?
@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.
@MuhammadFAH33M
@MuhammadFAH33M 2 ай бұрын
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 ❤
@m3tallicat
@m3tallicat 4 ай бұрын
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!!
@Kn2ght
@Kn2ght 6 ай бұрын
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) ?
@juliebinu3808
@juliebinu3808 5 ай бұрын
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
@yohanestiaras9233
@yohanestiaras9233 7 ай бұрын
Hi Greg, how about the code about save selected range with "many worksheet and many range" as picture
@bradosborne9299
@bradosborne9299 6 ай бұрын
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.
Excel VBA Macro: Autofilter All Values In A List (Dynamic Range)
14:42
DAD LEFT HIS OLD SOCKS ON THE COUCH…😱😂
00:24
JULI_PROETO
Рет қаралды 16 МЛН
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
Convertir de PDF a Excel
1:55
CEO Business Coach
Рет қаралды 1
Excel VBA Macro: Insert PivotTable (in Email Body)
9:19
greggowaffles
Рет қаралды 599
Do You Need to SWITCH from Excel VBA Macros to Office Scripts?
13:02
Leila Gharani
Рет қаралды 377 М.
How to Get List of File Names in a Folder using Excel
5:40
Excel Weez
Рет қаралды 6 М.
Excel VBA Macro: Save Selected Range as PDF (and Center on Page)
14:43
Excel VBA Macro: Paste Range (Table) As Image In Email Body
9:35
greggowaffles
Рет қаралды 34 М.
5 Excel Secrets You'll Be Embarrassed You Didn't Know
17:32
Excel Campus - Jon
Рет қаралды 126 М.
Excel VBA Save File as Cell Value
14:12
The Excel Cave
Рет қаралды 24 М.