设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

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

(以解決))在2010出現有問題--請幫忙解決一下

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

在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-11 21:22:08 | 只看该作者
是哪句出现错误,错误提示是什么?
3#
 楼主| 发表于 2017-5-11 23:31:04 | 只看该作者
tmtony 发表于 2017-5-11 21:22
是哪句出现错误,错误提示是什么?

是這句
With Application.FileSearch

点击这里给我发消息

4#
发表于 2017-5-12 10:32:37 | 只看该作者
.FileSearch 这个只限于在2003版本使用  其他版本是无效的  

可以使用dir 这个函数

举例

这个是获得路径下所有文件
myfile =dir(路径 & "*.*") '//*.* 这个表示是任何文件

do
  
myfile =dir
loop until len(myfile) =0

点击这里给我发消息

5#
发表于 2017-5-12 11:47:18 | 只看该作者
好不容易遇到个会的贴子,被抢了……
6#
 楼主| 发表于 2017-5-14 04:11:04 | 只看该作者
能不能幫忙改一下' 等學習下
7#
 楼主| 发表于 2017-5-16 17:05:38 | 只看该作者
pureshadow 发表于 2017-5-12 11:47
好不容易遇到个会的贴子,被抢了……

能不能幫忙改一下' 等學習下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-2 17:39 , Processed in 0.105465 second(s), 30 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

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