由于本人功力有限,找不到合适的代码,还望高人指教。 试写代码如下(错误),请有心人改正: '***************************************************************** Sub a() Dim nm As String Set fs = Application.FileSearch With fs .LookIn = "D:\ls" .FileType = msoFileTypeAllFiles If .Execute > 0 Then MsgBox "There were " & .FoundFiles.Count & _ " file(s) found." For j = 1 To .FoundFiles.Count nm = .FoundFiles(j) Call b(nm) ActiveWorkbook.SaveAs Filename:=nm, FileFormat:=xlExcel7 ActiveWorkbook.Close Next j Else MsgBox "There were no files found." End If End With End Sub '******************************************************************* Sub b(ByVal s As String) '估计此处错误 Dim i% Dim cnn As New ADODB.Connection, rst As New ADODB.Recordset cnn.Open "Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=d:\ls;" rst.Open "select * from s", cnn, adOpenStatic, adLockReadOnly '想用变量s表示文件名 Cells.Clear For i = 0 To rst.Fields.Count - 1 Cells(1, i + 1) = rst.Fields(i).Name Next i Cells(2, 1).CopyFromRecordset rst rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing End Sub
[此贴子已经被作者于2006-6-22 16:30:29编辑过] |