目录
7.插入图片:在excel修改插入图片的名字,和目标图片名字一致;然后选择目标图片名并点击"查看宏",再点击"执行"运行;
1.excel打开目标表格;
2.点开视图-宏-录制宏,可以改宏的名字或者选择默认;
3.然后点开视图-宏-查看宏
4.点编辑进去
5.修改代码:
(1)打开之后会显示有一堆代码
(2)将这个代码只要改地址直接贴到步骤(1)的模块代码
(3)呈现如图
Sub 批量插图()
On Error Resume Next
Application.ScreenUpdating = False
Dim MR As Range,sPath As String
sPath = "D:\临时" '设置图片位置
For Each MR In Selection
If Not IsEmpty(MR) And Dir(sPath & "\" & MR.Value & ".jpg") <> "" Then
MR.Select
ML = MR.Left
MT = MR.Top
MW = MR.Width
MH = MR.Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
sPath & "\" & MR.Value & ".jpg"
End If
Next
Set MR = Nothing
Application.ScreenUpdating = True
End Sub