该附件需要解压。解压后是一excel文件和一个文件夹。
文件夹里的有一组图片,图片的文件名,与excel文件里的姓名相对应。
现要求:
根据excel里的姓名,把文件夹里的图片名字改为相应的身份证名字。

解决方案 »

  1.   

    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
      

  2.   

    If Not f Like "#*" Then Name f As [b:b].Find(Split(f, ".")(0)).Offset(, 1) & ".jpg"该语句出错
      

  3.   

    这里面应该缺少一个end if 吧!
      

  4.   

    好像是缺少END IF 语句吧!
      

  5.   

    end if没有if语块问题应该出在 Name   f   As   [b:b].Find(Split(f,   ".")(0)).Offset(,   1)   &   ".jpg"
    这句上
      

  6.   

    经过验证的代码:引用 Microsoft ActiveX Data Objects 2.8 Library Private Sub Command1_Click()
    Dim cn As ADODB.Connection, rs As ADODB.Recordset
    Dim strFile As String, strPath As StringstrPath = "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