Resize an image in Excel (VBA) using cells
Solved
STVNA
Posted messages
32
Status
Member
-
STVNA Posted messages 32 Status Member -
STVNA Posted messages 32 Status Member -
Hello everyone!
In 2015, I posted this question: https://forums.commentcamarche.net/forum/affich-31772094-redimensionner-une-image-automatiquement-avec-excel-vba
We would now like to resize an image in Excel in such a way that when we enter a width and a height in cells, an image automatically resizes according to these values using VBA.
Thank you in advance!
In 2015, I posted this question: https://forums.commentcamarche.net/forum/affich-31772094-redimensionner-une-image-automatiquement-avec-excel-vba
We would now like to resize an image in Excel in such a way that when we enter a width and a height in cells, an image automatically resizes according to these values using VBA.
Thank you in advance!
1 answer
Hello,
Assuming there is only one image on the sheet, put this macro in the sheet module:
A1=height
A2=width
With the values in points.
Best regards.
Assuming there is only one image on the sheet, put this macro in the sheet module:
Private Sub Worksheet_Change(ByVal Target As Range) If [A1] <> "" And [A2] <> "" And IsNumeric([A1]) And IsNumeric([A2]) Then If Target.Address = "$a$1" Or Target.Address = "$a$2" Then With ActiveSheet.Pictures(1) .Height = [A1] .Width = [A2] End With End If End If End Sub
A1=height
A2=width
With the values in points.
Best regards.
Thank you for your reply!
But it doesn’t work. Where exactly should we place the macro?
Right-click on the tab of the sheet containing the image and click on "View Code". Paste the macro into the right side of the VBE window.
Daniel
And what do you mean by putting the values in points?
Thank you in advance.
The point is worth 1/72 of an inch and an inch is 2.54 cm. The workbook must be saved in .xlsm format and macros must be enabled. If you still have a problem, upload your workbook to mon-partage.fr and post the obtained link.
Daniel