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
If Not f Like "#*" Then Name f As [b:b].Find(Split(f, ".")(0)).Offset(, 1) & ".jpg"该语句出错
这里面应该缺少一个end if 吧!
好像是缺少END IF 语句吧!
end if没有if语块问题应该出在 Name f As [b:b].Find(Split(f, ".")(0)).Offset(, 1) & ".jpg" 这句上
经过验证的代码:引用 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
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
这句上
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