|
Name 旧文件名 As 新文件名
例如下面的过程将把当前mdb所在文件夹中一个叫“test.txt”的文件重命名为“MyText.txt”
至于通配符和随机路径什么的都可以变通实现
-------------------------------------
Sub myReName()
Dim strPath As String
Dim strOldName As String
Dim strNewName As String
Dim fs As Object
strPath = CurrentProject.Path
If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
strOldName = strPath & "test.txt"
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(strOldName) = False Then
MsgBox "文件" & strOldName & "不存在,无法重命名!", vbCritical
Exit Sub
End If
strNewName = strPath & "MyText.txt"
Name strOldName As strNewName
End Sub |
|