こんにちは。
画像の比率によってセルをはみ出るケースがあると思います。その場合の中央寄せはどのように考えていますか。
以下に、選択したセルに収まるよう画像調整し、TopもLeftもセル中央寄せにする例を挙げますので改造してください。
lang
1Sub hoge()
2 '画像読み込み
3 Dim shape As shape
4 Set shape = ActiveSheet.Shapes.AddPicture( _
5 Filename:="C:\temp\hoge.jpg", _
6 LinkToFile:=False, _
7 SaveWithDocument:=True, _
8 Left:=0, _
9 Top:=0, _
10 Width:=0, _
11 Height:=0)
12 shape.ScaleHeight 1, msoTrue
13 shape.ScaleWidth 1, msoTrue
14 shape.LockAspectRatio = msoTrue
15
16 '選択セル内に中央揃え
17 Dim margin As Integer
18 margin = 10
19 With shape
20 .Left = ActiveCell.Left
21 .Top = ActiveCell.Top
22 'セル内に画像サイズ調整
23 .Height = ActiveCell.Height - margin
24 If .Width > ActiveCell.Width Then
25 .Width = ActiveCell.Width - margin
26 End If
27 '横を中央寄せ
28 .Left = .Left + (ActiveCell.Width - shape.Width) / 2
29 '縦を中央寄せ
30 .Top = .Top + (ActiveCell.Height - shape.Height) / 2
31 End With
32
33 Set shape = Nothing
34End Sub
ご希望の動作を実現する仕組みがVBAに用意されているのか存じませんので、単純に位置調整しただけです。万が一、プロパティやメソッド一発で出来たらすみません。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。