▽1
●
いつか ベストアンサー |
一応これで条件を満たしていると思います。
Sub test() Dim y As Integer, i As Integer Dim fileName As String Dim wPic As Double, hPic As Double Dim wCell As Double, hCell As Double Dim wRate As Double, hRate As Double For i = 0 To 2 y = i * 2 + 2 fileName = ActiveSheet.Cells(1, y).Value y = y + 1 ActiveSheet.Cells(1, y).Select ActiveSheet.Pictures.Insert(fileName).Select Selection.Name = "pic" & y Set pic = ActiveSheet.Shapes("pic" & y) wPic = pic.Width hPic = pic.Height hCell = Rows(1).Height wCell = Columns(y).Width wRate = wPic / wCell hRate = hPic / hCell If wRate > hRate Then With pic .LockAspectRatio = True .Width = wCell End With Else With pic .LockAspectRatio = True .Height = hCell End With End If Next i End Sub