Resizing pictures already pasted to cells

jharlin

New Member
Joined
Feb 26, 2019
Messages
2
I have pictures already pasted into excel cells. I just want to write a macro that will let me change their sizes when I select them. I don't want to paste any new ones and everything I try gives me a 438 error object doesn't support this.
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,787
Office Version
  1. 365
Platform
  1. Windows
Try
- selecting a picture
- record a macro
- resize picture
- stop recording
- look at the macro
- it provides usable code.

Code:
Dim shp As Object: Set shp = Selection.ShapeRange
[I][COLOR=#006400]'position at top left of cell D5[/COLOR][/I]
    With Range("D5")
           shp.Top = .Top
           shp.Left = .Left
    End With
[I][COLOR=#006400]'should proportions stay the same? (default is msoTrue)[/COLOR][/I]
    shp.LockAspectRatio = msoTrue
    shp.LockAspectRatio = msoFalse
[COLOR=#006400][I]'set height and width like this[/I][/COLOR]
    shp.Width = 200
    shp.Height = 140
[I][COLOR=#006400]'to make width 50% of current width[/COLOR][/I]
    shp.ScaleWidth 0.5, msoFalse, msoScaleFromTopLeft
[I][COLOR=#006400]'to make height 3 times size of current height[/COLOR][/I]
    shp.ScaleHeight 3, msoFalse, msoScaleFromTopLeft
 
Last edited:

jharlin

New Member
Joined
Feb 26, 2019
Messages
2
Thank you. I thought about just recording a macro but didn't. However you are right it does produce code I can replicate for my other pictures. I have over 400 on here to do. I appreciate your help.
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,787
Office Version
  1. 365
Platform
  1. Windows
I have over 400 on here to do

400 pictures??

If you explain what needs doing to the pictures it is likely that more of the process can be automated via VBA
- for example VBA could loop through all the photos on a sheet to avoid each one being selected manually
- perhaps several could be selected and code applied in a loop
etc ..
 

Watch MrExcel Video

Forum statistics

Threads
1,109,487
Messages
5,529,156
Members
409,851
Latest member
Ingar
Top