excel高手请进-用VBA输入编号图片自动显示在excel中
PrivateSubCommandButton5_Click()'单击命令按钮DimrngAsRange,ML,MT,MW,MH,shpAsShape,n%,Myr&,i...
Private Sub CommandButton5_Click() '单击命令按钮
Dim rng As Range, ML, MT, MW, MH, shp As Shape, n%, Myr&, i&
On Error Resume Next
Sheet1.Activate
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape Then
shp.Delete
End If
Next
Myr = [a1].CurrentRegion.Rows.Count
For i = 2 To Myr Step 1
Set rng = Cells(i, 3).Resize(1, 1)
With rng
ML = .Left
MT = .Top
MW = .Width
MH = .Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
ThisWorkbook.Path & "\" & Cells(i, 2).Value & ".jpg" '照片名字单元格
End With
Next
[a1].Select
If Err.Number <> 0 Then Err.Clear: On Error GoTo 0
End Sub
这个代码只能表格和图片在同一个文件夹内,我想把表格放在E:\
然后图片放在E:\新图片 里面。上面的代码要怎么改!谢谢! 展开
Dim rng As Range, ML, MT, MW, MH, shp As Shape, n%, Myr&, i&
On Error Resume Next
Sheet1.Activate
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape Then
shp.Delete
End If
Next
Myr = [a1].CurrentRegion.Rows.Count
For i = 2 To Myr Step 1
Set rng = Cells(i, 3).Resize(1, 1)
With rng
ML = .Left
MT = .Top
MW = .Width
MH = .Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
ThisWorkbook.Path & "\" & Cells(i, 2).Value & ".jpg" '照片名字单元格
End With
Next
[a1].Select
If Err.Number <> 0 Then Err.Clear: On Error GoTo 0
End Sub
这个代码只能表格和图片在同一个文件夹内,我想把表格放在E:\
然后图片放在E:\新图片 里面。上面的代码要怎么改!谢谢! 展开
2个回答
展开全部
Private Sub CommandButton5_Click() '单击命令按钮
Dim rng As Range, ML, MT, MW, MH, shp As Shape, n%, Myr&, i&
On Error Resume Next
Sheet1.Activate
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape Then
shp.Delete
End If
Next
Myr = [a1].CurrentRegion.Rows.Count
For i = 2 To Myr Step 1
Set rng = Cells(i, 3).Resize(1, 1)
With rng
ML = .Left
MT = .Top
MW = .Width
MH = .Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
"E:\新图片\" & Cells(i, 2).Value & ".jpg" '照片名字单元格
End With
Next
[a1].Select
If Err.Number <> 0 Then Err.Clear: On Error GoTo 0
End Sub
表格放哪里无所谓
Dim rng As Range, ML, MT, MW, MH, shp As Shape, n%, Myr&, i&
On Error Resume Next
Sheet1.Activate
For Each shp In ActiveSheet.Shapes
If shp.Type = msoAutoShape Then
shp.Delete
End If
Next
Myr = [a1].CurrentRegion.Rows.Count
For i = 2 To Myr Step 1
Set rng = Cells(i, 3).Resize(1, 1)
With rng
ML = .Left
MT = .Top
MW = .Width
MH = .Height
ActiveSheet.Shapes.AddShape(msoShapeRectangle, ML, MT, MW, MH).Select
Selection.ShapeRange.Fill.UserPicture _
"E:\新图片\" & Cells(i, 2).Value & ".jpg" '照片名字单元格
End With
Next
[a1].Select
If Err.Number <> 0 Then Err.Clear: On Error GoTo 0
End Sub
表格放哪里无所谓
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询