LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Export picture as gif in Excel

I think www.irfanview.com does all you need, one of the
best freeware app's out there. It can Batch convert file
types and resize at the same time (see batch/advanced
options), and much else. Although for batch resizing you
might first need to sort portrait/landscape, which you
could do in code (unless you have hundreds probably not
worthwhile).

Some ideas for you to play with to tidy up your code:

You can add an embedded chart, correctly sized and
referenced in one go. Here's a snippet of my adaptation of
Robin's original -

Dim chObj As ChartObject
'get 'lWidth & lHeight dimensions of your picture per
Robin's original or resized to your needs. Add extra
border to each (say 4)

Set chObj = Worksheets("Sheet2"). _
ChartObjects.Add(10, 10, lWidth, lHeight)
'Don't need to set any source data.
With chObj.Chart
.Paste 'the previously copied picture
.ChartArea.Border.LineStyle = 0
.ChartArea.ClearContents
.Export strLocation, "GIF", False
End With
chObj.Delete

Rather than inserting the image direct to the chart, try
first inserting it to a sheet (if it's not already there),
resize it as required, copy it, and paste it to
the "sized" chart as above.

Perhaps change the file address before exporting:
StrLocation = strLocation & "_MyMod"

With Robin's original I found it necessary to put the
chart not on the activesheet. In the above it is
elsewhere in the activeworkbook, although for my purposes
I put it in another workbook. Requires a bit of
referencing and switching workbooks. But for what you are
currently doing this is not relevant.

I still think IrfanView is better!

Regards,
Sandy

PS Your newsreader appears not to like plus's and some
other characters

-----Original Message-----
Robin et al,

Have put your efforts to good effect and expanded on

them. As I got to work
on my problem, I realised that I needed to work with the

original photo
before it got onto the spreadsheet and also take account

of portrait photos
as well as landscape ones, and the aim was to reduce the

overall size of the
spreadsheet by making a small gif of the original photo,

to end up with a
usable databse of data and accompanying photos. The

resultant code helps to
show what I came up with, which, as a novice, I am quite

chuffed with!
Hopefully the notes make sense and this code can be of

use for others. If
anyone can tidy it up and make a neater job of it, I am

all ears!

Regards

Joe90

+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++

+++++

Sub ConvertToGif()

'Converts a base picture to gif using chart export
'and pastes gif to spreadsheet, also copes with

portrait/landscape pictures,
sizing to height only

'fname relates to a compiled filename on the spreadsheet

in column 2 of the
active row

'picture size is set to fit a cell 8 columns in from the

left, 105w x 150h
in points and allows for a border of 4 around it
'as pasting a picture into the chart forces a border on

the top and left

'working sheet is called "data", and the range is "a100"

which I know is
blank, to create a blank chart

'"Picture 17.gif" allows for a default picture in my main

application,
incase a picture is not available
'you can delete the IF/Else part for "filetoopen" if you

want

'thanks to Robin Hammond for the starting point on this!


Dim lWidth As Long
Dim lHeight As Long
Dim chtname
Dim chtnametrim
Static strlocation As String

filetoopen = Application.GetOpenFilename("Image Files

(*.gif;*.jpg;*.bmp),
*.gif;*.jpg;*.bmp")
fname = ActiveCell.Offset(0, -ActiveCell.Column 2)
strlocation = ThisWorkbook.Path & "\" & fname & ".gif"

If filetoopen = ThisWorkbook.Path & "\Picture 17.gif" Then
ActiveSheet.Pictures.Insert filetoopen
Else
Charts.Add
ActiveChart.SetSourceData Source:=Sheets("data").Range

("a100")
ActiveChart.Location Whe=xlLocationAsObject,

Name:="Data"
With ActiveChart
.Pictures.Insert filetoopen
.ChartArea.Border.LineStyle = 0
.ChartArea.ClearContents
If .Shapes(1).Width .Shapes(1).Height Then
.Shapes(1).LockAspectRatio = msoFalse
ActiveChart.Shapes(1).Width = 142
ActiveChart.Shapes(1).Height = 97
Else
ActiveChart.Shapes(1).Height = 97
End If
lWidth = ActiveChart.Shapes(1).Width
lHeight = ActiveChart.Shapes(1).Height
End With
chtname = ActiveChart.Name
chtnametrim = Mid(chtname, 6, 20)
ActiveSheet.Shapes(chtnametrim).Width = lWidth 8
ActiveSheet.Shapes(chtnametrim).Height = lHeight 8
ActiveChart.Export strlocation, "GIF", False

ActiveChart.ChartArea.Select
Selection.Clear
With Sheets("data")
ActiveCell.Offset(0, -ActiveCell.Column 9).Select
..Pictures.Insert strlocation
End With
End If
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++

+
Snip

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connect a number to a picture bank and import that picture to exce Dennis Hedo Excel Discussion (Misc queries) 1 March 22nd 10 02:17 PM
Export Excel tuncating leading zeros while export to excel from da RHBKV Setting up and Configuration of Excel 1 July 15th 09 01:48 PM
export re-order input fields to export file [csv] madisonpete Excel Worksheet Functions 0 November 30th 07 03:51 PM
insert a picture in to a comment but picture not save on hard disk Pablo Excel Discussion (Misc queries) 0 February 21st 07 03:48 PM
How to extract a picture from an Excel worksheet into a picture fi SARANJAI Excel Discussion (Misc queries) 10 June 12th 05 05:00 AM


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"