|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub Limonet()
Dim Cn As Object, StrSQL$, Path$, FileName$
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then Path = .SelectedItems(1) & "\" Else Exit Sub
End With
Set Cn = CreateObject("ADODB.Connection")
FileName = Dir(Path & "*.txt")
Do While FileName <> ""
If Not FileName Like "New*" Then
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Text;FMT=Delimited';Data Source=" & Path
StrSQL = "Select * From [" & FileName & "] Where Re>0"
Range("A2").CopyFromRecordset Cn.Execute(StrSQL)
Cn.Close
Cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & ThisWorkbook.FullName
Range("H2").CopyFromRecordset Cn.Execute("Select Left(Time,19) From [" & ActiveSheet.Name & "$H:H]")
Cn.Close
ActiveWorkbook.SaveAs FileName:=Path & "New-" & FileName, FileFormat:=xlCSV, CreateBackup:=False
End If
FileName = Dir
Loop
End Sub |
|