设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 3394|回复: 1
打印 上一主题 下一主题

固定單元格自动显示照片

[复制链接]
跳转到指定楼层
1#
发表于 2011-8-27 03:40:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 joyark 于 2011-8-30 02:55 编辑

固定單元格自动显示照片

1.第一種方法
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    With Image1
        Select Case ActiveCell.Address(False, False)
        Case "C4"
            P = "DC.JPG"
        Case "E4"
            P = "FG.JPG"
        Case "K5"
            P = "PR.JPG"
        Case Else
            .Visible = False
            Exit Sub
        End Select
        .Picture = LoadPicture(ThisWorkbook.Path & "\pic\" & P)
        .Visible = True
    End With
    With ActiveCell
        Image1.Top = .Top - Image1.Height / 2
        Image1.Left = .Left + .Width
    End With
End Sub
2.第二種方法

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column <> 1 Then Exit Sub    '如果需要只在第一列输入才产生效果 , 就在代码开头插入一句
'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 2, msoFalse, msoScaleFromTopLeft
            End With
        Else
            .Text Text:="找不到指定的图片"
        End If
    End With
    Application.DisplayCommentIndicator = xlCommentIndicatorOnly
End Sub

3.第三種方法
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count <> 1 Then Exit Sub
    Dim sPh As String
    Dim oCm As Comment
    Set oCm = Target.Comment
    sPh = ThisWorkbook.Path & "\pic\" & Target.Text & ".jpg"
    If Not oCm Is Nothing Then
        If Len(oCm.Text) = 0 Or Len(Dir(sPh)) Then oCm.Delete
    End If
    If Len(Dir(sPh)) Then
        With Target.AddComment
            .Visible = True
            .Text Text:=""
            .Shape.Select True
        End With
        With Selection.ShapeRange
            .Fill.UserPicture ThisWorkbook.Path & "\pic\" & Target.Text & ".jpg"
            .ScaleWidth 1.7, msoFalse, msoScaleFromTopLeft
            .ScaleHeight 4, msoFalse, msoScaleFromTopLeft
        End With
        Application.DisplayCommentIndicator = xlCommentIndicatorOnly
    End If
End Sub

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅

点击这里给我发消息

2#
发表于 2011-8-27 08:05:28 | 只看该作者
赞一个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-2 06:22 , Processed in 0.089405 second(s), 26 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表