Excel精英培训网

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

[已解决]如何让筛选的图片,在原来位置?

[复制链接]
发表于 2009-9-14 10:02 | 显示全部楼层 |阅读模式
eZ7h22jF.rar (670.3 KB, 下载次数: 40)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2009-9-14 10:07 | 显示全部楼层    本楼为最佳答案   

Sub ad()
    Dim pth As String
    Dim pthname As String
    Dim rng1 As Range
    Dim rng2 As Range
            On Error Resume Next
            pth = ThisWorkbook.Path & "\" & "New Folder\"
            Application.ScreenUpdating = False
                        With Sheet1
                          Set rng1 = .Cells(1, 1)
                                If Len(rng1.Text) Then
                                     Set rng2 = .Cells(1, 3)
                                            .Pictures(rng2.Address(0, 0)).Delete
                                            pthname = Dir(pth & rng1.Text & "*")
                                        With ActiveSheet.Pictures.Insert(pth & pthname)
                                                        .Name = rng2.Address(0, 0)
                                                        .Height = rng2.Height
                                                        .Top = rng2.Top
                                                        .Left = rng2.Left

                                                        .Width = rng2.Width
                                        End With
                                End If
                        End With
            Application.ScreenUpdating = True
           
End Sub
[此贴子已经被作者于2009-9-14 10:08:03编辑过]
回复

使用道具 举报

 楼主| 发表于 2009-9-14 10:28 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2009-9-14 10:47 | 显示全部楼层

不要按按钮就能实现变化,如何实现呢? 谢谢

回复

使用道具 举报

发表于 2009-9-14 11:17 | 显示全部楼层

以下代码放到Sheet1中

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Address = "$A$1" Then
        Dim pth As String
        Dim pthname As String
        Dim rng1 As Range
        Dim rng2 As Range
                On Error Resume Next
                pth = ThisWorkbook.Path & "\" & "New Folder\"
                Application.ScreenUpdating = False
                            With Sheet1
                              Set rng1 = .Cells(1, 1)
                                    If Len(rng1.Text) Then
                                         Set rng2 = .Cells(1, 3)
                                                .Pictures(rng2.Address(0, 0)).Delete
                                                pthname = Dir(pth & rng1.Text & "*")
                                            With ActiveSheet.Pictures.Insert(pth & pthname)
                                                            .Name = rng2.Address(0, 0)
                                                            .Height = rng2.Height
                                                            .Top = rng2.Top
                                                            .Left = rng2.Left
                                                            .Width = rng2.Width
                                            End With
                                    End If
                            End With
                Application.ScreenUpdating = True

    End If
End Sub

回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-14 03:59 , Processed in 0.393390 second(s), 7 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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