1.在某一CELL中输入图片的绝对路径,移开焦点后,在该cell中自动显示图片,并且图片可根据列的大小自动适应.
请高手帮忙!!
请问EXCEL能做到吗??
2 个解决方案
#1
捕获Sheet的change事件,获得输入的路径,打开并显示图片即可
#2
夸大其词了,半点挑战性都没有,上当了。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Shape, r As Single
If Dir(Target.Text) <> "" Then
ActiveSheet.Pictures.Insert(Target.Text).Select
Selection.ShapeRange.Top = Target.Top
Selection.ShapeRange.Left = Target.Left
r = Target.Width / Selection.ShapeRange.Width
Selection.ShapeRange.ScaleWidth r, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight r, msoFalse, msoScaleFromTopLeft
Rows(Target.Row).RowHeight = Selection.ShapeRange.Height
Selection.Placement = xlMoveAndSize
Selection.PrintObject = True
Target.Select
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Shape, r As Single
If Dir(Target.Text) <> "" Then
ActiveSheet.Pictures.Insert(Target.Text).Select
Selection.ShapeRange.Top = Target.Top
Selection.ShapeRange.Left = Target.Left
r = Target.Width / Selection.ShapeRange.Width
Selection.ShapeRange.ScaleWidth r, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight r, msoFalse, msoScaleFromTopLeft
Rows(Target.Row).RowHeight = Selection.ShapeRange.Height
Selection.Placement = xlMoveAndSize
Selection.PrintObject = True
Target.Select
End If
End Sub
#1
捕获Sheet的change事件,获得输入的路径,打开并显示图片即可
#2
夸大其词了,半点挑战性都没有,上当了。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Shape, r As Single
If Dir(Target.Text) <> "" Then
ActiveSheet.Pictures.Insert(Target.Text).Select
Selection.ShapeRange.Top = Target.Top
Selection.ShapeRange.Left = Target.Left
r = Target.Width / Selection.ShapeRange.Width
Selection.ShapeRange.ScaleWidth r, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight r, msoFalse, msoScaleFromTopLeft
Rows(Target.Row).RowHeight = Selection.ShapeRange.Height
Selection.Placement = xlMoveAndSize
Selection.PrintObject = True
Target.Select
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim a As Shape, r As Single
If Dir(Target.Text) <> "" Then
ActiveSheet.Pictures.Insert(Target.Text).Select
Selection.ShapeRange.Top = Target.Top
Selection.ShapeRange.Left = Target.Left
r = Target.Width / Selection.ShapeRange.Width
Selection.ShapeRange.ScaleWidth r, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight r, msoFalse, msoScaleFromTopLeft
Rows(Target.Row).RowHeight = Selection.ShapeRange.Height
Selection.Placement = xlMoveAndSize
Selection.PrintObject = True
Target.Select
End If
End Sub