Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you Don, works charmingly.
Kind regards |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
delete first 4 letters in a cell | Excel Discussion (Misc queries) | |||
i delete a program that converts number into letters | Excel Discussion (Misc queries) | |||
How do change a column of data in capitol letters to small letters | Excel Discussion (Misc queries) | |||
How to delete in batch the same color format letters in a cell | Excel Worksheet Functions | |||
Delete all letters? | Excel Discussion (Misc queries) |