VBA EXCEL图片匹配宏修改

2025-03-01 15:34:01
推荐回答(2个)
回答1:

Sub Button1_Click()
Dim MR As Range
For Each MR In Selection
If Not IsEmpty(MR) Then
MR.Select
ML = MR.Left + 1
MT = MR.Top + 1
MW = MR.Width - 2
MH = MR.Height - 2

ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture "C:\123\test.bmp"
Selection.ShapeRange.Line.Visible = msoFalse
End If
Next
End Sub

回答2:

Sub 按钮48_单击()
On Error Resume Next
Dim MR As Range
For Each MR In Selection
If Not IsEmpty(MR) Then
MR.Select
ML = MR.Left + 1
MT = MR.Top + 1
MW = MR.Width - 2
MH = MR.Height - 2
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
ActiveWorkbook.Path & "\pic\" & MR.Value & ".jpg"
End If
Next
Selection.ShapeRange.Line.Visible = msoFalse '设置为无边框
End Sub