Resizing a picture in excel using VBA

Derby2007

Board Regular
Joined
Nov 15, 2007
Messages
50
Hello,

As the title goes this is as simple as it gets. The macro worked good when I was using excel 2003 but now that I have 2007 everything works for except the resizing (Picture.Width & Picture. Height).

Code:
Sub AddImage()
Dim strPath As String
Dim strFile As String
Dim Picture As Object
Dim Response As String
Dim C As Range
strPath = "C:\\Photos\"
 
For Each C In Range("A1", Range("A65536").End(xlUp))
    If C <> 0 Then
        With C.Offset(0, 1)
            Set Picture = Nothing
            On Error Resume Next
            Set Picture = Sheets("Raw Pix").Pictures.Insert(strPath & C.Value & ".jpg")
            Picture.Top = .Top
            Picture.Left = .Left
            Picture.LockAspectRatio = msoTrue
[B]            Picture.Width = 157
            Picture.Height = 138[/B]

        
    End With
    End If
     
NextC:
Next C
End Sub

I have tried to record some macros while I am resizing the pictures but to no avail the macros are blank.

Please help

Thanks!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try changing these lines:

Code:
            Picture.ShapeRange.LockAspectRatio = msoTrue
            Picture.ShapeRange.Width = 157
            'Picture.ShapeRange.Height = 138

Note that since you're locking the aspect ratio, you only need to specify just the width or the height.

HTH!
 
Upvote 0
I am sorry I do not want to lock the apect ratio.

Does anybody know what the VBA code for "Relative to original picture size" AND "Move and size with cells"

Thanks!!!
 
Upvote 0
In that case, try:
Code:
            Picture.ShapeRange.LockAspectRatio = msoFalse
            Picture.Placement = xlMoveAndSize
            Picture.ShapeRange.Width = 0.5 * Picture.Width
            Picture.ShapeRange.Height = 0.75 * Picture.Height

And adjust percentages as needed.
 
Upvote 0
SWEEEET!!!!

I had been tinkering with your code and made some adjustments but this worked..

Code:
Picture.Top = .Top
            Picture.Left = .Left
            Picture.ShapeRange.LockAspectRatio = msoFalse
            Picture.Placement = xlMoveAndSize
            Picture.ShapeRange.Width = 157
            Picture.ShapeRange.Height = 138

Thank you, DSCG, very much for your help!!!!
 
Upvote 0
I that I had but I really don't.

It seems that the width is works fine but what makes that the height continue to change? I even tried to size some photos to the same size but it seems by the time it gets to the last row its not even with the same row it should be.

Any picture wizards out there?

Thanks in advance!
 
Upvote 0
I that I had but I really don't.

It seems that the width is works fine but what makes that the height continue to change? I even tried to size some photos to the same size but it seems by the time it gets to the last row its not even with the same row it should be.

Any picture wizards out there?

Thanks in advance!

Even i am looking for the same answer. as picture size get changed after paste special.
 
Upvote 0

Forum statistics

Threads
1,213,496
Messages
6,113,995
Members
448,539
Latest member
alex78

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top