|
本帖最后由 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
这样的功能..
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
|
|