Bill
Something like this should help you out
without shelling......
Sub ReName_File()
Dim OldName As String
Dim NewName As String
OldName = "D:\t.txt": NewName = "D:\ok.txt"
Name OldName As NewName
End Sub
HTH
Ivan
Thanks Ivan
That almost worked...get a "runtime error 58" "File already exists" error, so need some code to ignore that error and continue...
Thanks for your help...
Bill
How do I ignore "runtime error 58" "File already exists" error??
Re: How do I ignore "runtime error 58" "File already exists" error??
Bill here is how I have used it;
Sub ReName_File()
Dim OldName As String
Dim NewName As String
Dim IsThere, Exists As Boolean
EnterAgain:
OldName = Application.InputBox("Enter name of File to change", "Change name of File", "C:\", Type:=2)
If OldName = "False" Then End
IsThere = Dir(OldName)
If IsThere = "" Then MsgBox "File does not exist!": GoTo EnterAgain
Exists = True
EnterAgain1:
NewName = Application.InputBox("Enter New name of File", "Change name of File", "C:\", Type:=2)
If NewName = "False" Then End
IsThere = Dir(NewName)
If IsThere <> "" Then MsgBox "FileName already exists!" & Chr(13) & _
"You need to enter a new name": GoTo EnterAgain1
Exists = True
'OldName = "D:\t.txt": NewName = "D:\ok.txt"
On Error Resume Next
Name OldName As NewName
If Err.Number <> 0 Then MsgBox Err.Number & " " & Err.Description
End Sub
HTH
Ivan