Save as picture... in excel VBA

amaresh achar

Board Regular
Joined
Dec 9, 2016
Messages
108
Office Version
  1. 365
Platform
  1. Windows
Hi...

I have a circle and rectangle shape (grouped together) in Sheet2.

I want to save that entire group as single picture ***.jpg file (using VBA code)

Can anyone please help me with this...??

Version: Office 365 16.0.16130.20306
Windows 10
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
One would think it was simple but it requires a couple steps.

You need to copy and paste it into a chart then save the chart.

VBA Code:
Sub Save_Pic()
Dim shp As Shape, flnm As String
Set shp = ActiveSheet.Shapes("MyGroupShape")

flnm = "C:\Users\---\Pictures\MyGroupShape.jpg" ' your file name
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Set chrt = ActiveSheet.ChartObjects(1)
With shp
chrt.Width = .Width
chrt.Height = .Height
.CopyPicture
End With
ActiveChart.Paste
chrt.Chart.Export Filename:=flnm
chrt.Delete
End Sub


I have a named group in sheet1,

1686054605697.png
 
Upvote 0
One would think it was simple but it requires a couple steps.

You need to copy and paste it into a chart then save the chart.

VBA Code:
Sub Save_Pic()
Dim shp As Shape, flnm As String
Set shp = ActiveSheet.Shapes("MyGroupShape")

flnm = "C:\Users\---\Pictures\MyGroupShape.jpg" ' your file name
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Set chrt = ActiveSheet.ChartObjects(1)
With shp
chrt.Width = .Width
chrt.Height = .Height
.CopyPicture
End With
ActiveChart.Paste
chrt.Chart.Export Filename:=flnm
chrt.Delete
End Sub


I have a named group in sheet1,

View attachment 93031
Thanks for your response Sir... Yes I previously tried these options, but the image file saved with this technique has very lower resolution (around 90dpi)

But the MS Excel from latest office 365 offers an option to save a shape or group of shapes just by Right click ---> Save Picture As... and save it in any convenient formats...(at 330 dpi) any idea about how to use that option?


doubt.png
 
Upvote 0
HTH. Dave
 
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,516
Members
449,168
Latest member
CheerfulWalker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top