VBA for resize and align picture.

Mousepad522

New Member
Joined
Jul 29, 2022
Messages
5
Office Version
  1. 2013
Platform
  1. Windows
Hi, I want to make a VBA Macro in Excel for resizing and centering pictures that are already in a worksheet.

The pictures are in cells. I was hoping to just adjust the picture height and width.

Any help would be great, I'm new to macros.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
shapes(1) is now within the borders of its topleftcell
VBA Code:
Sub rezisen()
     With ActiveSheet
          Set shp = .Shapes(1)     'your shape
          Set c = shp.TopLeftCell
          With shp
               .Left = c.Left + 1
               .Top = c.Top + 1
               .Width = c.Offset(, 1).Left - .Left - 1
               .Height = c.Offset(1).Top - .Top - 1
          End With
     End With
End Sub
 
Upvote 0
shapes(1) is now within the borders of its topleftcell
VBA Code:
Sub rezisen()
     With ActiveSheet
          Set shp = .Shapes(1)     'your shape
          Set c = shp.TopLeftCell
          With shp
               .Left = c.Left + 1
               .Top = c.Top + 1
               .Width = c.Offset(, 1).Left - .Left - 1
               .Height = c.Offset(1).Top - .Top - 1
          End With
     End With
End Sub
Thanks!! If I replace TopLeftCell with CenterCell will that place the picture in the middle? (I'm using the VBA to adjust and move barcodes for scanning so needs a space around it.)
 
Upvote 0
no, you see twice +1 and twice -1, if you increment that number, you get more space around, how many, just give it a try. 28 points for 1 cm 72 points for an inch.
 
Upvote 0
no, you see twice +1 and twice -1, if you increment that number, you get more space around, how many, just give it a try. 28 points for 1 cm 72 points for an inch.
Ok thanks!! I'll give it a try Monday!
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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