您的位置:程序门 -> vb -> vba



能否通过excel字段的内容对另一个文件夹里面的文件名进行替换


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


能否通过excel字段的内容对另一个文件夹里面的文件名进行替换
发表于:2007-12-29 17:08:45 楼主
该附件需要解压。解压后是一excel文件和一个文件夹。
文件夹里的有一组图片,图片的文件名,与excel文件里的姓名相对应。
现要求:
根据excel里的姓名,把文件夹里的图片名字改为相应的身份证名字。
该帖包含附件:
发表于:2007-12-30 01:30:131楼 得分:0
sub   macro1()
chdir   thisworkbook.path   &   "\1\"
dim   f   as   string
f   =   dir(thisworkbook.path   &   "\1\*.jpg")
while   f   >   ""
if   not   f   like   "#*"   then   name   f   as   [b:b].find(split(f,   ".")(0)).offset(,   1)   &   ".jpg"
f   =   dir
wend
end   sub
发表于:2008-01-02 11:09:592楼 得分:0
文件夹找不到啊
发表于:2008-01-03 08:50:593楼 得分:0
if   not   f   like   "#*"   then   name   f   as   [b:b].find(split(f,   ".")(0)).offset(,   1)   &   ".jpg"

该语句出错
发表于:2008-01-03 09:44:534楼 得分:0
这里面应该缺少一个end   if   吧!
发表于:2008-01-03 10:01:095楼 得分:0
好像是缺少end   if   语句吧!
发表于:2008-01-04 08:25:486楼 得分:0
end   if没有if语块

问题应该出在   name       f       as       [b:b].find(split(f,       ".")(0)).offset(,       1)       &       ".jpg"
这句上
发表于:2008-01-04 09:41:137楼 得分:0
经过验证的代码:

引用   microsoft   activex   data   objects   2.8   library  
c/c++ code
private sub command1_click() dim cn as adodb.connection, rs as adodb.recordset dim strfile as string, strpath as string strpath = "e:\test\" set cn = new adodb.connection cn.open "provider=microsoft.jet.oledb.4.0;data source=" & strpath & "1.xls;extended properties=excel 8.0;" set rs = cn.EXECute("select * from [sheet1$]") strpath = "e:\test\1\" do until rs.eof strfile = dir(strpath & rs.fields("姓名") & ".jpg") if strfile > "" then name strpath & strfile as strpath & rs.fields("身份证号码") & ".jpg" end if rs.movenext loop set rs = nothing cn.close set cn = nothing end sub


快速检索

最新资讯
热门点击