Rename file to txt

cesarelias

New member
Local time
Today, 13:30
Joined
May 10, 2009
Messages
8
Hi,

Does anyone know how to rename a file.ret to file.txt.
I tried this above code, but I get error.
I Would to change extensions to txt several files automatic.
One help would be great
thanx
cesar

'Dim strpth, strnewpth
'Dim strfile
'strpth = "c:\ajustetxt\"
'strfile = Dir(strpth, vbNormal)

'strnewpth = Left(strfile, Len(strfile) - 3) & "txt"
'Name strfile As strnewpth
 
Access Help
Name Statement Example
This example uses the Name statement to rename a file. For purposes of this example, assume that the directories or folders that are specified already exist. On the Macintosh, “HD:” is the default drive name and portions of the pathname are separated by colons instead of backslashes.

Dim OldName, NewName
OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
Name OldName As NewName ' Rename file.

OldName = "C:\MYDIR\OLDFILE": NewName = "C:\YOURDIR\NEWFILE"
Name OldName As NewName ' Move and rename file.


David
 
hi Dhake,
I have several files extd11110001.ret, 'extv11110003.ret and extv11110004.ret etc. I want to rename txt file. I tried the name statement above, but it get error.
do you help me again?
thanx
cesar

'Private Sub Comando100_Click()
'Dim OldName, NewName
'OldName = "OLDFILE": NewName = "NEWFILE" ' Define file names.
'OldName = "C:\ajustetxt\OLDFILE": NewName = "C:\ajustetxt\NEWFILE"
'Name OldName As NewName ' Move and rename file.
'End Sub
 
hi,

I managed to create the code to rename files with other extensions to txt files, through another code I found here in the forum. I am leaving here the code to help others who need it
thanx
cesar

Private Sub Comando100_Click()
ChDir ("C:\ajustetxt\")
Dim stNewName As String, stOldName
Dir_List = "C:\ajustetxt\"
Directory = Dir(Dir_List)
If Len(Directory) > 0 Then
Do
filename = "C:\ajustetxt\" & Directory
stOldName = filename
stnameonly = Left(stOldName, Len(stOldName) - 3)
'MsgBox "stnameOnly = " & stnameonly
stNewName = stnameonly & "txt"
Name stOldName As stNewName
Directory = Dir
Loop Until Len(Directory) = 0 'And stFirst <> filename
End If

End Sub


 

Users who are viewing this thread

Back
Top Bottom