工作中经常用到这个,是网上找的代码,简单修改了下。
Excel 其实只能单纯的用来做数据,并不适合打印和排版,尤其是设计部分功能缺失严重,不得不使用一些辅助工具来完成一些机械的操作,比如Excel工具箱、VBA,按键精灵等等。

Sub 图片自动居中对齐()
‘运行前提是,选择了某一个单元区域
‘可以是一行,一列,一个矩形区域,或者若干单元格的组合(不在同行同列的组合,比如选择D1/C2/C5)
Dim c As Shape
For Each c In ActiveSheet.Shapes ‘对当前表中所有图形进行遍历
If Not Application.Intersect(c.TopLeftCell, Selection) Is Nothing Then ‘判断图形是否在选择的单元格区域内
If c.TopLeftCell.MergeCells Then
With c.TopLeftCell.MergeArea
c.Left = .Left + .Width / 2 – c.Width / 2
c.Top = .Top + .Height / 2 – c.Height / 2
End With
Else
With c.TopLeftCell
c.Left = .Left + .Width / 2 – c.Width / 2
c.Top = .Top + .Height / 2 – c.Height / 2
End With
End If
End If
Next c
End Sub