Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Insert picture, resize to specific width, keeping height proportio

#1. I'd use As Double because I want to include the decimal portion of the
number.

#2.
Set Pic = PRM.Pictures.Insert("C:\Documents and Settings\Olab\" & _
"My Documents\0- Wear Testing\Sketches\" & sStyle & ".jpg")

(notice the extra ()'s.)



justme wrote:

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!


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Insert picture, resize to specific width, keeping height propo


Thanks, Dave! Your suggestion certainly worked! It was my bad...parens
were in original post by Tom O. BTW, I know Double works, but I'm not
exactly sure of all the different data types that allow decimal points. I
read the help definitions, but I'm still not sure. Could you please explain
in lay terms the difference between the different data types that allow
decimals?

thank you!!!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Insert picture, resize to specific width, keeping height propo

if you search for "data type summary" in VBA-Help you get a good overview.

Double is an 8-byte floating number, which works good in your case. You
could also use Single (4-byte floating number) which is smaller, but I don't
know if it would change a lot in your project.

hth

Carlo

"justme" wrote:


Thanks, Dave! Your suggestion certainly worked! It was my bad...parens
were in original post by Tom O. BTW, I know Double works, but I'm not
exactly sure of all the different data types that allow decimal points. I
read the help definitions, but I'm still not sure. Could you please explain
in lay terms the difference between the different data types that allow
decimals?

thank you!!!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Insert picture, resize to specific width, keeping height propo

Hi Carlo,

thank you for your reply, but like I said, I already read the vba help
summary and I really don't understand the terms used like "floating point",
etc. etc.

I was hoping for someone could explain in lay terms the difference between
the different data types that allow decimals.



p.s. in case anyone is pays attention to my picture resizing sub where you
only know the width, I caught a boo boo and here's the revised sub:

SUMFB.Activate
SUMFB.Cells(15, 16).Select '''VARIABLE PRM
Set pSketch = SUMFB.Pictures.Insert("C:\Documents and Settings\Olab\My
Documents\0- Wear Testing\Sketches\" & sStyle & ".jpg") '''VARIABLE PRM
With pSketch
PicHt = .Height
PicWd = .Width
.Select
.Width = 240
PicRatio = .Width / PicWd
.Height = PicHt * PicRatio
.Top = .Top - .Height + 1
End With


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 179
Default Insert picture, resize to specific width, keeping height propo

Floating Point means decimal point.

So, if you want to use decimal point you can choose between:
double and single

if you want to have whole numbers you can choose between all the rest
(including single and double)

Hope that I spoke in lay terms, as I am also a lay ;)

For your Resize sub you can shorten it to:
----------------------------------------------------------
SUMFB.Activate
'i'm not sure, if you really need to select this cell!
SUMFB.Cells(15, 16).Select '''VARIABLE PRM
Set pSketch = SUMFB.Pictures.Insert("C:\Documents and Settings\Olab\My
Documents\0- Wear Testing\Sketches\" & sStyle & ".jpg") '''VARIABLE PRM
With pSketch
PicRatio = .Width / .Height
.Width = 240
.Height = .Width * PicRatio
'not sure, what you want to achieve with the following line
.Top = .Top - .Height + 1
End With
----------------------------------------------------------

hth

Carlo
"justme" wrote:

Hi Carlo,

thank you for your reply, but like I said, I already read the vba help
summary and I really don't understand the terms used like "floating point",
etc. etc.

I was hoping for someone could explain in lay terms the difference between
the different data types that allow decimals.



p.s. in case anyone is pays attention to my picture resizing sub where you
only know the width, I caught a boo boo and here's the revised sub:

SUMFB.Activate
SUMFB.Cells(15, 16).Select '''VARIABLE PRM
Set pSketch = SUMFB.Pictures.Insert("C:\Documents and Settings\Olab\My
Documents\0- Wear Testing\Sketches\" & sStyle & ".jpg") '''VARIABLE PRM
With pSketch
PicHt = .Height
PicWd = .Width
.Select
.Width = 240
PicRatio = .Width / PicWd
.Height = PicHt * PicRatio
.Top = .Top - .Height + 1
End With

Reply
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
Insert, position, and resize a picture w/ Macro John Excel Discussion (Misc queries) 1 July 10th 07 07:21 PM
Resize Last Row to Fill a Page Width Sloth Excel Discussion (Misc queries) 0 February 17th 06 10:28 PM
resize row height and column height Tom Setting up and Configuration of Excel 3 April 3rd 05 02:03 PM
resize row and colomn height Tom Excel Programming 4 March 11th 05 04:22 PM
get a picture width and height without inserting the picture Dorothy Excel Programming 1 January 13th 05 05:06 AM


All times are GMT +1. The time now is 03:37 AM.

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

About Us

"It's about Microsoft Excel"