Save Range to File as Image (tif)

Jeffrey Mahoney

Well-known Member
Joined
May 31, 2015
Messages
2,773
Office Version
  1. 365
Platform
  1. Windows
I can't believe this is not easier for me. I looked at many posts and tried to duplicate their results. When I manually copy a range as a picture, paste it, and Save as Picture, it seems so easy. I even used some code that first pasted the picture into a chart, but I get an empty file after exporting.

Please help with the code to export a shape into a TIF file.


VBA Code:
Sub SaveRangeToFile()

  Dim MatNum As String
  Dim FileName As String
  Dim Shp As Shape
  Dim Sht As Worksheet

  Set Sht = ActiveSheet
  
  Range("SaveRange").Select
  Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
  MatNum = Range("MaterialNum").Value
  FileName = MatNum & ".tif"
  Range("P4").Select
  
  Sht.Pictures.Paste.Select
  Set Shp = Sht.Shapes(Sht.Shapes.Count)
  
  Shp.Export FileName:=FileName, Filtername:="TIF"     '<<<<< There is no option to export a shape
  
  
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
I even used some code that first pasted the picture into a chart

Try that code again, but save the file as .jpg
Then rename the file x.jpg as x.tif
Check if that way the x.tif file works for you.
 
Upvote 0
Try that code again, but save the file as .jpg
Then rename the file x.jpg as x.tif
Check if that way the x.tif file works for you.

This code works to save a chart as a jpg or png format. When I try to export it as TIF format, the image is blank. TIF is an uncompressed format and I'd like to use that.

Question is, why can't I export an image pasted in Excel without adding it to a Chart? I can do it manually, and I can export it as a TIF file.

VBA Code:
Sub SaveRangeToFile()

  Dim MatNum As String
  Dim FileName As String
  Dim Shp As Shape
  Dim Sht As Worksheet
  Dim Cht As Chart

  Set Sht = ActiveSheet
  
  Range("SaveRange").Select
  Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
  MatNum = Range("MaterialNum").Value
  FileName = MatNum & ".png"
  Range("P4").Select
  
  Sht.Pictures.Paste.Select
  Set Shp = Sht.Shapes(Sht.Shapes.Count)
  
  
  Set Cht = Charts.Add
  Cht.ChartArea.Clear
  'Cht.Name = "PicChart" & (Rnd() * 10000)
  Set Cht = Cht.Location(Where:=xlLocationAsObject, Name:=Sht.Name)
  Cht.ChartArea.Width = Shp.Width
  Cht.ChartArea.Height = Shp.Height
  Cht.Parent.Border.LineStyle = 0

  'Paste range as image to chart
  Shp.Copy
  Cht.ChartArea.Select
  Cht.Paste

  Cht.Export FileName:=FileName, Filtername:="png"
  Cht.Select
  Cht.Delete
  Shp.Delete
  
  
  
End Sub
 
Upvote 0
Maybe you can download a software that converts jpg to tif.
And maybe you can use it from VBA passing it the parameters of the source file destination file.
 
Upvote 0
Thanks for the offer. The quality of the images saved to a JPG file is already ruined. Converting it to a TIF file doesn't bring back the original data.
 
Upvote 0
jpg was the example, I mean to use an extension to which excel does have access and then with a software convert it to tif
 
Upvote 0
The expedient way is to export the range to a graphic format excel supports. I like .png. Then open with Paint and save to .tif (or .tiff)
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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