Hi All,
I have been trying to alter a code which I previously saw but to no avail...
basically, i am trying to resize all SELECTED pictures to fit into the size of the cells which I have wanted.
however while I can do for one pic at a time with the needed result, I cannot do it if I selected multiple pictures...
any idea why?? I have pasted the code below for all the experts out there to help me solve the mystery...
Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim pic As Picture
If TypeName(Selection) = "DrawingObjects" Then
For Each pic In Selection
FitIndividualPic pic
Next pic
Else
FitIndividualPic Selection
End If
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro." & " Num" & count
End Sub
Public Sub FitIndividualPic(pic As Object)
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
Dim Gap As Single
Gap = 3
With pic
PicWtoHRatio = (.Width / .Height)
End With
With pic.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With pic
.Width = .TopLeftCell.Width - Gap
.Height = .Width / PicWtoHRatio - Gap
End With
Case Else
With pic
.Height = .TopLeftCell.RowHeight - Gap
.Width = .Height * PicWtoHRatio - Gap
End With
End Select
With pic
.Top = .TopLeftCell.Top + Gap
.Left = .TopLeftCell.Left + Gap
End With
End Sub
I have been trying to alter a code which I previously saw but to no avail...
basically, i am trying to resize all SELECTED pictures to fit into the size of the cells which I have wanted.
however while I can do for one pic at a time with the needed result, I cannot do it if I selected multiple pictures...
any idea why?? I have pasted the code below for all the experts out there to help me solve the mystery...
Public Sub FitPic()
On Error GoTo NOT_SHAPE
Dim pic As Picture
If TypeName(Selection) = "DrawingObjects" Then
For Each pic In Selection
FitIndividualPic pic
Next pic
Else
FitIndividualPic Selection
End If
Exit Sub
NOT_SHAPE:
MsgBox "Select a picture before running this macro." & " Num" & count
End Sub
Public Sub FitIndividualPic(pic As Object)
Dim PicWtoHRatio As Single
Dim CellWtoHRatio As Single
Dim Gap As Single
Gap = 3
With pic
PicWtoHRatio = (.Width / .Height)
End With
With pic.TopLeftCell
CellWtoHRatio = .Width / .RowHeight
End With
Select Case PicWtoHRatio / CellWtoHRatio
Case Is > 1
With pic
.Width = .TopLeftCell.Width - Gap
.Height = .Width / PicWtoHRatio - Gap
End With
Case Else
With pic
.Height = .TopLeftCell.RowHeight - Gap
.Width = .Height * PicWtoHRatio - Gap
End With
End Select
With pic
.Top = .TopLeftCell.Top + Gap
.Left = .TopLeftCell.Left + Gap
End With
End Sub