When you say you "edited" I’m guessing you changed that code snippet:
With oImage
.Left = oCell.Left
.Top = oCell.Top
.Width = oCell.Width
.Height = oCell.Height
End With
For that reason:
With oImage
.Left = oCell.Left
.Top = oCell.Top
.Width = oCell.Width / 1.2
.Height = oCell.Height / 1.2
End With
That is, in practice you have reduced the size of the image. So, to center the image in the cell (without worrying about how much factor has been applied) the easiest way is for you to add to the top coordinates (Left
and Top
) half the size of the cell and half the size of the image (which then needs to be calculated before, depending on the factor you are applying). Try so:
factor = 1.2 ' Separei em uma variável só pra deixar claro que você pode
' mudar sem precisar mexer nas duas linhas finais.
With oImage
.Width = oCell.Width / factor
.Height = oCell.Height / factor
.Left = oCell.Left + oCell.Width / 2 - .Width / 2
.Top = oCell.Top + oCell.Height / 2 - .Height / 2
End With
And by the way how it works if there are 2 or more sheets in the file?
– Ricardo