Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1678|回复: 4

[已解决]更改图片的显示方式

[复制链接]
发表于 2012-11-15 13:15 | 显示全部楼层 |阅读模式
附件功能的是,点击指定区域单元格时,根据单元格的内容,显示指定目录下对应名称的图片。
  目前是靠右显示,能否帮忙改成在左边显示当内容在底部时,向上显示,效果如下图:

003.png    004.png

                             测试附件: Pic.zip (124.66 KB, 下载次数: 50)
发表于 2012-11-15 16:29 | 显示全部楼层
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim p$, x%
    If Target.Column = 19 And Target <> "" And Target.Count = 1 Then
        If ActiveSheet.Pictures.Count Then ActiveSheet.Pictures.Delete
        p = ThisWorkbook.Path & "\" & Target & ".jpg"
        If Dir(p) <> "" Then
            With ActiveSheet.Pictures.Insert(p)
                .Left = Target.Left - .Width
                Application.EnableEvents = False
                x = Cells.SpecialCells(xlCellTypeLastCell).Row
                Application.EnableEvents = True
                If Target.Row < x / 2 Then
                    .Top = Target.Top
                Else
                    .Top = Target.Top + Target.Height - .Height
                End If
            End With
        End If
    End If
End Sub

评分

参与人数 1 +1 收起 理由
fightingd + 1 很给力!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2012-11-15 17:54 | 显示全部楼层
本帖最后由 fightingd 于 2012-11-15 17:56 编辑

还差一点,显示是在当前单元格所在行的下一行。
自己看看示例图片就明白了,非常感谢。

还有一点,点击非指定位置或空单元格时,应该没有图片显示才对。
回复

使用道具 举报

发表于 2012-11-15 18:07 | 显示全部楼层    本楼为最佳答案   
本帖最后由 爱疯 于 2012-11-15 18:21 编辑

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim p$, x%
    If ActiveSheet.Pictures.Count Then ActiveSheet.Pictures.Delete
    If Target.Count <> 1 Then End
    If Target = "" Then End
    If Target.Column <> 19 Then End
    p = ThisWorkbook.Path & "\" & Target & ".jpg"
    If Dir(p) <> "" Then
        With ActiveSheet.Pictures.Insert(p)
            .Left = Target.Left - .Width
            Application.EnableEvents = False
            x = Cells.SpecialCells(xlCellTypeLastCell).Row
            Application.EnableEvents = True
            If Target.Row < x / 2 Then
                .Top = Target.Top + Target.Height
            Else
                .Top = Target.Top - .Height
            End If
        End With
    End If
End Sub

评分

参与人数 1 +1 收起 理由
fightingd + 1 很给力!

查看全部评分

回复

使用道具 举报

 楼主| 发表于 2012-11-15 18:23 | 显示全部楼层
正是想要的结果,结贴。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-4-20 05:37 , Processed in 0.476177 second(s), 17 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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