View Full Version : Create Image of selected cells and save outside of Excel

04-13-2007, 11:54 AM
I have a spreadsheet that once created and verified needs to be put into a totally non-editable format (to be accomplished automatically using VBA). My boss suggested using our network pdf printer to convert the excel file into a pdf. I was hoping that there could be another way.

I found this information in another post:

Select the range
Ctrl + C to copy
Select paste location
Shift +Alt +E
P to paste or N to paste link

And I came up with this code (would be tweaked to fit):

Sub Macro2()
With Cells.Interior
.ColorIndex = 2
.Pattern = xlSolid
End With

Windows("Job 123456 - Run Test - Press 1009 - 4.12.2007.xls").Activate 'This is the existing workbook
Windows("Book5").Activate 'The workbook that was just added
End Sub

I was wondering if it was possible to create this picture in something other than Excel. Perhaps something like Paint, where I can save the file as a bitmap or a jpeg or whatever. Whatever I do, I need to accomplish it all with coding.


Simon Lloyd
04-13-2007, 02:12 PM
You could try saving it as a Single File Web document, its like a picture!
something like this but you can record it using the macro recorder, don't forget when it asks you to save to choose worksheet rather than workbook!
ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\My Documents\test.mht", FileFormat:= _
xlWebArchive, CreateBackup:=False
With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _
"C:\Documents and Settings\My Documents\test.mht", "Sheet1", "", _
xlHtmlStatic, "Book1_2148", "")
.Publish (True)
.AutoRepublish = False
End With

04-13-2007, 02:52 PM
Sub Macro1()
Application.CutCopyMode = False
ActiveWindow.DisplayGridlines = False

End Sub

04-13-2007, 10:09 PM
I use the following:

Sub ExportCellsAsPicture()
Const FName As String = "D:\My Documents\My Pics\Pics.jpg"
Dim pic_rng As Range
Dim ShTemp As Worksheet
Dim ChTemp As Chart
Dim PicTemp As Picture
Application.ScreenUpdating = False
Set pic_rng = Worksheets("FileNameHere").Range("B1:F28") 'Set your range here
Set ShTemp = Worksheets.Add
ActiveChart.Location Where:=xlLocationAsObject, Name:=ShTemp.Name
Set ChTemp = ActiveChart
pic_rng.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set PicTemp = Selection
With ChTemp.Parent
.Width = PicTemp.Width + 8
.Height = PicTemp.Height + 8
End With
ChTemp.Export Filename:="D:\My Documents\My Pics\Pics.jpg", FilterName:="jpg"
Application.DisplayAlerts = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Works like a charm for me.
You can substitude the .jpg to .gif if so desired.
It'll put a picture named "Pics.jpg" in the folder "D:\My Documents\My Pics of the range selected.

Ivan F Moala
04-14-2007, 05:56 AM
You could also try something like.........


04-16-2007, 05:28 AM
You could try saving it as a Single File Web document, its like a picture!

I had thought about saving as the Single Web File, but my problem with it is that I several option button and text boxes on my form. Internet Explorer doesn't like to show these active controls right away (security reasons). I'd rather not make my users have to constantly grant access to this "blocked content". Plus, the values on the controls can be "changed" (I know the changes cannot actually be saved, but I don't want the appearance of editability.)

I'm thinking that I will stick with the paste as a picture. It meets my needs and greatly reduces the file size. Hopefully the boss finds it to be a good idea as well!

Thanks to everyone for your input.