花看半开,酒饮微醺

嚼得菜根,百事可为

Excel将插入的图片在单元格居中代码

一、选中需要居中的图片(ALT+A全选)

 

二、按ALT+F11打开Microsoft Visual Basic for Applications窗口:

  1、点击:插入-模块:

   2、输入代码:

Sub dq()
 
Dim shp As Shape
 
For Each shp In ActiveSheet.Shapes
 
shp.Left = (shp.TopLeftCell.Width - shp.Width) / 2 + shp.TopLeftCell.Left
 
shp.Top = (shp.TopLeftCell.Height - shp.Height) / 2 + shp.TopLeftCell.Top
 
Next
 
End Sub

  3、直接关闭窗口。

 

三、按ALT+F8,打开宏命令窗口:

四、执行dq宏命令。

五、完。

 

posted @ 2023-06-29 10:00  太阳和野花  阅读(600)  评论(0编辑  收藏  举报