-
Sep 5th, 2008, 03:15 PM
#1
Export an Image from Excel Sheet to Hard Drive
I was thinking to include this in the code bank for a long time but didn't think it was that important but after when I replied to one of the threads today, I did a quick search in the forum and found that many members have asked this question in the past (including me) So here it is. I am pasting the code for your reference. Hope it benefits someone... If it does then do leave a comment here
Excel unfortunately doesn't allow you to directly export jpeg, gif images. However It does let you easily export flowcharts, charts etc... so the key is to trick Excel. And we can do that by creating a temp chart and pasting the picture in the chart. We need to work with the dimensions a little bit but after that it very easy to export the image. Here is the code...
I have commented the code so that it would be easy to understand...
vb Code:
Option Explicit
'You need to select a picture before running this code
'else it will give you error'
Sub PictureExport()
Dim TempChart As String, Picture2Export As String
Dim PicWidth As Long, PicHeight As Long
Picture2Export = Selection.Name
'Store the picture's height and width in a variable
With Selection
PicHeight = .ShapeRange.Height
PicWidth = .ShapeRange.Width
End With
'Add a temporary chart in sheet1
Charts.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
Selection.Border.LineStyle = 0
TempChart = Selection.Name & " " & Split(ActiveChart.Name, " ")(2)
With ActiveSheet
'Change the dimensions of the chart to suit your need
With .Shapes(TempChart)
.Width = PicWidth
.Height = PicHeight
End With
'Copy the picture
.Shapes(Picture2Export).Copy
'Paste the picture in the chart
With ActiveChart
.ChartArea.Select
.Paste
End With
'Finally export the chart
.ChartObjects(1).Chart.Export Filename:="Sample.jpg", FilterName:="jpg"
'Destroy the chart. You may want to delete it...
.Shapes(TempChart).Cut
End With
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 19th, 2010, 09:09 PM
#2
Re: Export an Image from Excel Sheet to Hard Drive
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Dec 7th, 2011, 10:27 AM
#3
New Member
Re: Export an Image from Excel Sheet to Hard Drive
OR you could just save your excel sheet as a web page. There will be a file and a folder. All your pictures will be in that folder in their original file type.
-
Dec 29th, 2011, 02:23 AM
#4
New Member
Re: Export an Image from Excel Sheet to Hard Drive
Originally Posted by kyle012012
OR you could just save your excel sheet as a web page. There will be a file and a folder. All your pictures will be in that folder in their original file type.
I agree with your thoughts! Thanks!
________________________________
r4 3dsps3 jb2crown3ds
Last edited by mandykk; Dec 30th, 2011 at 08:40 PM.
-
Feb 4th, 2013, 04:26 AM
#5
Lively Member
Re: Export an Image from Excel Sheet to Hard Drive
[QUOTE=mandykk;4110797]I agree with your thoughts! Thanks!
using the VBA code from the first post, the acquired image has a lower quality (is blurry somehow) than when you save the excel file as web page and use the image in the HTML folder.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|