|
opelwang 发表于 2011-7-14 22:59
版主,测试了下代码,效果不错,只是没加容错处理。如果图片不存在或找不到对应的图片,报错。
能否 ...
图片名字不存在时,就直接不显示,这样不好吗?你一个这么大的工作表中除了这个还需要有其他内容吧.
如果真要这样就更简单了
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count <> 1 Then Exit Sub
Dim sPh As String
On Error Resume Next
sPh = ThisWorkbook.Path & "\pic\" & Target.Text & ".jpg"
Target.Comment.Delete
With Target.AddComment
.Visible = True
.Text Text:=""
.Shape.Select True
If Len(Dir(sPh)) Then
With Selection.ShapeRange
.Fill.UserPicture ThisWorkbook.Path & "\pic\" & Target.Text & ".jpg"
.ScaleWidth 1.7, msoFalse, msoScaleFromTopLeft
.ScaleHeight 4, msoFalse, msoScaleFromTopLeft
End With
Else
.Text Text:="找不到指定的图片"
End If
End With
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub
|
评分
-
查看全部评分
|