Delete some letters

  • Thread starter Thread starter darkblue
  • Start date Start date
D

darkblue

Hi
Currently i am doing it manually but i was wondering if this can be
done by vba.
I have several documents to be read in a folder. When i read them i
put "-R" at the end of doc name. But before moving some of them to the
archive (another folder) i have to delete this "-R" bits. So folder
"archive" must have no docs ending with "-R". How can i do that ? Any
idea ?
Thanks in advance
 
Hi
Currently i am doing it manually but i was wondering if this can be
done by vba.
I have several documents to be read in a folder. When i read them i
put "-R" at the end of doc name. But before moving some of them to the
archive (another folder) i have to delete this "-R" bits. So folder
"archive" must have no docs ending with "-R". How can i do that ? Any
idea ?
Thanks in advance

Should do it. You can move withIN the same macro

Sub renamefiles()
Dim fn As String
Dim mPath As String
mPath = "C:\aa\" 'location of files
ChDir mPath
fn = Dir("*.xls") 'or your ext
Do While fn <> ""
If Right(fn, 6) = "-R.xls" Then
'MsgBox sFil
Dim OldName, NewName
OldName = fn
NewName = Left(fn, Len(fn) - 6) & ".xls"
Name OldName As NewName ' Rename file.
End If
fn = Dir
Loop
End Sub
 
Hi
Currently i am doing it manually but i was wondering if this can be
done by vba.
I have several documents to be read in a folder. When i read them i
put "-R" at the end of doc name. But before moving some of them to the
archive (another folder) i have to delete this "-R" bits. So folder
"archive" must have no docs ending with "-R". How can i do that ? Any
idea ?
Thanks in advance
Resending

Sub renamefiles()
Dim fn As String
Dim mPath As String
mPath = "C:\aa\" 'location of files
ChDir mPath
fn = Dir("*.xls") 'or your ext
Do While fn <> ""
If Right(fn, 6) = "-R.xls" Then
'MsgBox sFil
Dim OldName, NewName
OldName = fn
NewName = Left(fn, Len(fn) - 6) & ".xls"
Name OldName As NewName ' Rename file.
End If
fn = Dir
Loop
End Sub
 
Back
Top