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 Where:=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
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Robin Hammond said:
Thanks Dave, just saw the thread. Was playing bad golf.
Robin Hammond
www.enhanceddatasystems.com
Check out our XspandXL add-in
Dave Peterson said:
For some reason, you lost the plusses in that expression:
lWidth = lWidth .Columns(nCounter).Width
lHeight = lHeight .Rows(nCounter).Height
there's a "space, Plus sign, space" directly in front of the .columns
and
"picture
of a gif.