Excel精英培训网

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

[已解决]关于批量改文件名的 求助

[复制链接]
发表于 2013-6-5 09:47 | 显示全部楼层 |阅读模式
本帖最后由 1testvba 于 2013-6-5 09:48 编辑

各位老师好.
我有如下代码:

Sub test_Click()
    Dim MyFile, MyPath, MyName, i%
    MyPath = ThisWorkbook.Path & "\test\"
    MyFile = Dir(MyPath & "测试*.txt")
    Do While MyFile <> ""    ' 开始循环。
        i = i + 1
        MyName = "ok_.txt"
        Name MyPath & MyFile As MyPath & MyName
        MyFile = Dir    ' 查找下一个目录。
    Loop
End Sub

这个代码 是把 test文件夹下 所有包含 测试*.txt 都改成ok_.txt
若是测试*.txt 多的话. VBA代码报错.(文件已存在)
我要修改哪里.
才能实现
ok_1.txt
ok_2.txt
ok_3.txt

这样的功能..
最佳答案
2013-6-5 09:51
Sub test_Click()
    Dim MyFile, MyPath, MyName, i%
    MyPath = ThisWorkbook.Path & "\test\"
    MyFile = Dir(MyPath & "测试*.txt")
    Do While MyFile <> ""    ' 开始循环。
        i = i + 1
        MyName = "ok" & i & "_.txt"   
    Name MyPath & MyFile As MyPath & MyName
        MyFile = Dir    ' 查找下一个目录。
    Loop
End Sub
发表于 2013-6-5 09:51 | 显示全部楼层    本楼为最佳答案   
Sub test_Click()
    Dim MyFile, MyPath, MyName, i%
    MyPath = ThisWorkbook.Path & "\test\"
    MyFile = Dir(MyPath & "测试*.txt")
    Do While MyFile <> ""    ' 开始循环。
        i = i + 1
        MyName = "ok" & i & "_.txt"   
    Name MyPath & MyFile As MyPath & MyName
        MyFile = Dir    ' 查找下一个目录。
    Loop
End Sub
回复

使用道具 举报

 楼主| 发表于 2013-6-5 10:11 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-21 12:04 , Processed in 0.290949 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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