ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete some letters (https://www.excelbanter.com/excel-programming/444713-delete-some-letters.html)

darkblue

Delete some letters
 
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

Don Guillett[_2_]

Delete some letters
 
On Jun 26, 2:45*pm, darkblue wrote:
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


Don Guillett[_2_]

Delete some letters
 
On Jun 26, 2:45*pm, darkblue wrote:
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

darkblue

Delete some letters
 
Thank you Don, works charmingly.

Kind regards


All times are GMT +1. The time now is 06:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com