Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007: top of screen "File Name [Group]", how to remove [Grou Lightjag Excel Discussion (Misc queries) 3 April 2nd 23 07:08 PM
how to remove gridlines from part of a worksheet only joe Excel Worksheet Functions 12 March 27th 08 07:21 PM
remove a dash from part numbers Mr Happy Excel Discussion (Misc queries) 3 May 25th 06 09:06 PM
How to remove link to other files in Excel 2000 Oleg Excel Discussion (Misc queries) 2 February 14th 06 06:36 AM
Remove file Protection from an Excel workbook file from others whistler_z Excel Discussion (Misc queries) 2 December 12th 05 06:35 PM


All times are GMT +1. The time now is 11:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"