设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

[以解決] 在2010不能使用, 在2003使用正常,希望各位高人幫忙修改

[复制链接]
跳转到指定楼层
1#
发表于 2017-5-16 18:41:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 joyark 于 2017-5-22 08:52 编辑

在2010不能使用,希望各位高人幫忙修改
在2003使用正常的資料如下
第一,表格
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
With Target.Cells(1)
    If (.Column = 3 Or .Column = 7 Or .Column = 11 Or .Column = 15) And .Row Mod 4 = 2 Then
        addPic Target.Cells(1)
    End If
End With
End Sub
改了這部份1
Sub fdjpg(nm As String)
With Application.FileSearch
    .LookIn = ThisWorkbook.Path
    .SearchSubFolders = True
    .Filename = nm & ".jpg"
    If .Execute <> 0 Then
        nm = .FoundFiles(1)
    Else
        nm = ""
    End If
End With

第二,是宏
Sub addPic(tgRng As Range)    '表格
    Dim rng As Range
    Dim nm As String
    Dim shp As Shape
    With tgRng
        nm = .Text
        Selection.Cut
        Set rng = .Offset(1, 0).Resize(1, 1)    '地址
    End With改了這部份2
    fdjpg nm
    If nm <> "" Then
        rng.Worksheet.Pictures.Insert(nm).Select

        With Selection
            .Top = rng.Top + 1
            .Left = rng.Left + 1
            .Placement = xlMoveAndSize
            .Width = rng.Width - 1
            .Height = rng.Height - 1
        End With
    Else
       ' MsgBox nm & "沒有圖片"
    End If
End Sub更改了這部份1
Dim fpath
Sub fdjpg(myfolder, myfile)
Set fso = CreateObject("scripting.filesystemobject")
Set ff = fso.getfolder(myfolder)
For Each f In ff.Files
    If f.Name = myfile Then fpath = f: Exit Sub
Next
For Each fd In ff.subfolders
    fdjpg fd, myfile
Next
End Sub
更改了這部份2
addpic中
fdjpg thisworkbook.path,nm & ".jpg"
if fpath<>"" then
rng.Worksheet.Pictures.Insert(fpath).Select
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2017-5-16 19:29:18 | 只看该作者
FileSearch方法已取消
用dir或别的替代
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-5 20:08 , Processed in 0.084168 second(s), 25 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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