View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
justme justme is offline
external usenet poster
 
Posts: 68
Default Insert picture, resize to specific width, keeping height proportio

Hi,

My sub will insert a picture into my template and resize the width to 240.
The original picture aspect ratio will vary, so I will not know the resize
height ahead of time. I have written the below sub all by myself so far, so
there's a good chance there's something wrong with it. It resizes the height
proportionately to the width, then places the bottom left corner of the
picture at the bottom left corner of cell K11.

Dim PicHt As Double
Dim PcWd As Double
Dim PicRatio As Double

PRM.Activate
PRM.Cells(12, 11).Select
PRM.Pictures.Insert "C:\Documents and Settings\Olab\My Documents\0- Wear
Testing\Sketches\" & sStyle & ".jpg"
With PRM.Pictures("Picture 8")
PicHt = .Height
PicWd = .Width
PicRatio = PicHt / PicWd
.Select
.Width = 240
.Height = PicHt * PicRatio
.Top = .Top - .Height + 1
End With

It seems to work so far, but I have two specific questions and if you see
anything else I could do better, please let me know.

1. Is Double the correct data type to use? I know Long doesn't work because
it's integers only. I tried Decimal, but my vba doesn't recognize this data
type. All I need is for it to go to 2 decimal points. I'm not exactly sure
what Double means, even after reading the Help definition. What data type is
best for this?

2. Is there a way to specify the picture to manipulate as the last picture
inserted instead of "Picture 8"? I tried using this method I found in a post:

Dim Pic as Picture
Dim sStyle As String

sStyle = PRM.Cells(5, 2).Text
Set Pic = PRM.Pictures.Insert "C:\Documents and Settings\Olab\My
Documents\0- Wear Testing\Sketches\" & sStyle & ".jpg"
Pic.Selet

But an error states that the quotation mark after "Sketches\" should be the
end of statement. It does work with a normal file path, but I think my
variable is throwing it off.

Thank you!

Thanks!