Excel VBA Code Picture fit automatically to Cell

Public Sub FitPic()

On Error GoTo NOT_SHAPE
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
With Selection
PicWtoHRatio = .Width / .Height
End With
With Selection.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With Selection
.Width = .TopLeftCell.Width
.Height = .Width / PicWtoHRatio
End With
Case Else
With Selection
.Height = .TopLeftCell.RowHeight
.Width = .Height * PicWtoHRatio
End With
End Select
With Selection
.Top = .TopLeftCell.Top
.Left = .TopLeftCell.Left
End With
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro."
End Sub

Comments

  1. What about multiple photos aligned together??

    ReplyDelete
  2. Please the VB code for multiple people images aligned together in one click

    ReplyDelete
  3. Please provide the VB code for multiple images aligned together in one click. mzubairrafiq4@gmail.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Physical properties of Liquid

Characteristics and Limitations of computer:

1.4 Bent Axis Piston Pump