Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1910|回复: 9

[已解决]读取数据后另存

[复制链接]
发表于 2011-1-15 21:13 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2011-1-16 02:40 | 显示全部楼层
本帖最后由 liz917 于 2011-1-16 14:37 编辑

Option Explicit
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
    i = 1
    For Each f1 In ff
        oldname = f1.Name
        newname = Replace(oldname, ".csv", ".xls")
        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

回复

使用道具 举报

发表于 2011-1-16 07:07 | 显示全部楼层
回复

使用道具 举报

发表于 2011-1-16 08:44 | 显示全部楼层
学习         
回复

使用道具 举报

发表于 2011-1-16 09:42 | 显示全部楼层
楼主哪去了?2楼的代码应该可以的。
回复

使用道具 举报

 楼主| 发表于 2011-1-16 16:50 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

发表于 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
回复

使用道具 举报

发表于 2011-1-16 21:10 | 显示全部楼层
楼上的太厉害了,好好学习~~
回复

使用道具 举报

 楼主| 发表于 2011-1-17 11:18 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

 楼主| 发表于 2011-1-18 20:02 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-7 23:33 , Processed in 0.552360 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表