ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   can I remove part of a file name (LO) from a group of excel files (https://www.excelbanter.com/excel-discussion-misc-queries/151703-can-i-remove-part-file-name-lo-group-excel-files.html)

Geekedersch

can I remove part of a file name (LO) from a group of excel files
 
my output from testing always has (LO) in the file names. no parenthesis.
To use the files we have to delete the LO from each file name. Is there a
way to remove the LO from the whole group at one time?
Thanks for any help.
Elaine

Chip Pearson

can I remove part of a file name (LO) from a group of excel files
 
IF the "LO" you want to omit is the first occurrence of the letters "LO" in
the file name, AND ALL the files are in the same folder AND you want to
possibly rename all the files in the folder, you can use code like the
following. Change the lines marked with '<<<<< to the appropriate values.


Sub RenameFiles()

Dim FName As String
Dim RenameCount As Long
Dim ErrCount As Long
Dim RenameStr As String
Dim ErrStr As String
Dim ReplaceName As String

ChDrive "C:" '<<<<< CHANGE
ChDir "C:\Test" '<<<<< CHANGE

FName = Dir("*.xls")
On Error Resume Next
Do Until FName = vbNullString
ReplaceName = Replace(expression:=FName, Find:="LO", _
Replace:=vbNullString, Count:=1, compa=vbTextCompare)
Err.Clear
Name FName As ReplaceName
If Err.Number = 0 Then
RenameStr = RenameStr & vbCrLf & ReplaceName
RenameCount = RenameCount + 1
Else
ErrStr = ErrStr & vbCrLf & FName
ErrCount = ErrCount + 1
End If
FName = Dir()
Loop

MsgBox "Files Renamed: " & CStr(RenameCount) & vbCrLf & RenameStr
If ErrCount 0 Then
MsgBox "Error renaming files: " & CStr(ErrCount) & vbCrLf & ErrStr
End If

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Geekedersch" wrote in message
...
my output from testing always has (LO) in the file names. no parenthesis.
To use the files we have to delete the LO from each file name. Is there a
way to remove the LO from the whole group at one time?
Thanks for any help.
Elaine



Geekedersch

can I remove part of a file name (LO) from a group of excel fi
 
they are text documents
2731B1LO
2731B2LO
2731B3LO
2731B4LO
2731B5LO
2731INB
2731INL
2731INR
2731L1LO
2731L2LO
2731L3LO
2731L4LO
2731L5LO


"Chip Pearson" wrote:

IF the "LO" you want to omit is the first occurrence of the letters "LO" in
the file name, AND ALL the files are in the same folder AND you want to
possibly rename all the files in the folder, you can use code like the
following. Change the lines marked with '<<<<< to the appropriate values.


Sub RenameFiles()

Dim FName As String
Dim RenameCount As Long
Dim ErrCount As Long
Dim RenameStr As String
Dim ErrStr As String
Dim ReplaceName As String

ChDrive "C:" '<<<<< CHANGE
ChDir "C:\Test" '<<<<< CHANGE

FName = Dir("*.xls")
On Error Resume Next
Do Until FName = vbNullString
ReplaceName = Replace(expression:=FName, Find:="LO", _
Replace:=vbNullString, Count:=1, compa=vbTextCompare)
Err.Clear
Name FName As ReplaceName
If Err.Number = 0 Then
RenameStr = RenameStr & vbCrLf & ReplaceName
RenameCount = RenameCount + 1
Else
ErrStr = ErrStr & vbCrLf & FName
ErrCount = ErrCount + 1
End If
FName = Dir()
Loop

MsgBox "Files Renamed: " & CStr(RenameCount) & vbCrLf & RenameStr
If ErrCount 0 Then
MsgBox "Error renaming files: " & CStr(ErrCount) & vbCrLf & ErrStr
End If

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Geekedersch" wrote in message
...
my output from testing always has (LO) in the file names. no parenthesis.
To use the files we have to delete the LO from each file name. Is there a
way to remove the LO from the whole group at one time?
Thanks for any help.
Elaine



simplymidori[_2_]

can I remove part of a file name (LO) from a group of excel fi
 
I have a similiar situation only I need to remove hyphens (-) out of my files.

example: 07-17-07-213310-13188-0.CSV file

Can I use this same script only change "LO" to "-" and file type?


"Chip Pearson" wrote:

IF the "LO" you want to omit is the first occurrence of the letters "LO" in
the file name, AND ALL the files are in the same folder AND you want to
possibly rename all the files in the folder, you can use code like the
following. Change the lines marked with '<<<<< to the appropriate values.


Sub RenameFiles()

Dim FName As String
Dim RenameCount As Long
Dim ErrCount As Long
Dim RenameStr As String
Dim ErrStr As String
Dim ReplaceName As String

ChDrive "C:" '<<<<< CHANGE
ChDir "C:\Test" '<<<<< CHANGE

FName = Dir("*.xls")
On Error Resume Next
Do Until FName = vbNullString
ReplaceName = Replace(expression:=FName, Find:="LO", _
Replace:=vbNullString, Count:=1, compa=vbTextCompare)
Err.Clear
Name FName As ReplaceName
If Err.Number = 0 Then
RenameStr = RenameStr & vbCrLf & ReplaceName
RenameCount = RenameCount + 1
Else
ErrStr = ErrStr & vbCrLf & FName
ErrCount = ErrCount + 1
End If
FName = Dir()
Loop

MsgBox "Files Renamed: " & CStr(RenameCount) & vbCrLf & RenameStr
If ErrCount 0 Then
MsgBox "Error renaming files: " & CStr(ErrCount) & vbCrLf & ErrStr
End If

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


"Geekedersch" wrote in message
...
my output from testing always has (LO) in the file names. no parenthesis.
To use the files we have to delete the LO from each file name. Is there a
way to remove the LO from the whole group at one time?
Thanks for any help.
Elaine




All times are GMT +1. The time now is 07:02 PM.

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