|
发表于 2011-1-16 17:37
|
显示全部楼层
本楼为最佳答案
回复 a409902202 的帖子
Sub 按钮1_Click()
Dim str1$, str2$, oldname$, newname$, i%, r%, k%, arr
Dim fso As Object, f As Object, ff As Object, f1 As Object
str2 = ActiveWorkbook.Path
Set fso = CreateObject("scripting.filesystemobject")
Set f = fso.GetFolder(str2 & "\data\")
Set ff = f.Files
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.Cells.Clear '新加
i = 1
For Each f1 In ff
oldname = f1.Name
newname = Replace(oldname, ".csv", ".xlsm") '改
' Workbooks.Add
k = FreeFile
Open f1 For Input As #k
r = 1
Do
Line Input #k, str1
arr = Split(str1, ",")
ActiveSheet.Cells(r, 1).Resize(1, UBound(arr) + 1) = arr
r = r + 1
Loop Until EOF(k)
ActiveWorkbook.SaveAs Filename:=str2 & "\over\" & newname
' ActiveWorkbook.Close
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Set fso = Nothing: Set f = Nothing: Set ff = Nothing: Set f1 = Nothing
End Sub
|
|