Excel中利用宏使在一个单元格输入内容后自动插入图片,关键是怎么把插入的图片缩小点
不会把表格边框线遮挡PrivateSubWorksheet_Change(ByValTargetAsRange)IfTarget.Column=1ThensfileNam...
不会把表格边框线遮挡
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
sfileName = ThisWorkbook.Path & "\" & Target.Value & ".jpg"
On Error GoTo err01
With Target.Offset(0, 1)
Shapes.AddPicture(sfileName, True, True, .Left, .Top, .Width, .Height).Select
Selection.Placement = xlMoveAndSize
End With
End If
Cells(1, 1).Select
Exit Sub
err01:
If err.Number = 1004 Then MsgBox "当前目录下没有名称为:" & Target.Value & ".jpg,的图片"
End Sub
我用的宏 展开
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
sfileName = ThisWorkbook.Path & "\" & Target.Value & ".jpg"
On Error GoTo err01
With Target.Offset(0, 1)
Shapes.AddPicture(sfileName, True, True, .Left, .Top, .Width, .Height).Select
Selection.Placement = xlMoveAndSize
End With
End If
Cells(1, 1).Select
Exit Sub
err01:
If err.Number = 1004 Then MsgBox "当前目录下没有名称为:" & Target.Value & ".jpg,的图片"
End Sub
我用的宏 展开
1个回答
展开全部
略作调整,您试试看:
将图片的位置和图片的宽度、高度作了调整。
如果需要将图片调的更小,可以将数字调大一些即可。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
sfileName = ThisWorkbook.Path & "\" & Target.Value & ".jpg"
On Error GoTo err01
With Target.Offset(0, 1)
Shapes.AddPicture(sfileName, True, True, .Left + 1, .Top + 1, .Width - 2, .Height - 2).Select '位置和图片的宽度、高度作了调整
Selection.Placement = xlMoveAndSize
End With
End If
Cells(1, 1).Select
Exit Sub
err01:
If Err.Number = 1004 Then MsgBox "当前目录下没有名称为:" & Target.Value & ".jpg,的图片"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询