Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Rename multiple csv files eliminating (-) hyphens from the label.

How do I rename multiple csv files eliminating (-) hyphens from the label.

example of a file name

07-24-07-075339-2308-0-sales.CSV

to

07240707533923080sales.CSV

Thanks in advance,

SimplyM

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Rename multiple csv files eliminating (-) hyphens from the label.

This code will do it: copy it, and paste it as a macro into a
spreadsheet. Before you run it you'll need to change the line that
currently says
FilePath = "c:\CSV Files\"
to
FilePath = "c:\Your Exact Directory Tree Here\"

The code finds all the files in that directory with a CSV extension
and renames them without hyphens to an XYZ extension. Then it changes
the XYZ extensions to CSV. If the code changed the non-hyphenated form
to CSV right away the program would loop endlessly.


Sub CSV_No_Hyphen()
Dim OrigName As String
Dim FilePath As String
Dim NewName As String
Dim SheetName
Dim K As Byte

FilePath = "c:\CSV Files\"
OrigName = Dir(FilePath & "*.csv")
Do While OrigName < ""
For K = 1 To Len(OrigName) - 4
If Mid(OrigName, K, 1) < "-" Then
NewName = NewName & Mid(OrigName, K, 1)
End If
Next K

FileCopy FilePath & OrigName, FilePath & NewName & ".xyz"
NewName = ""
Kill FilePath & OrigName

OrigName = Dir
Loop

OrigName = Dir(FilePath & "*.xyz")
Do While OrigName < ""
NewName = Mid(OrigName, 1, Len(OrigName) - 4)

FileCopy FilePath & OrigName, FilePath & NewName & ".csv"
NewName = ""
Kill FilePath & OrigName

OrigName = Dir
Loop

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default Rename multiple csv files eliminating (-) hyphens from the label.

Thanks Dave it worked like a charm!

"simplymidori" wrote:

How do I rename multiple csv files eliminating (-) hyphens from the label.

example of a file name

07-24-07-075339-2308-0-sales.CSV

to

07240707533923080sales.CSV

Thanks in advance,

SimplyM

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
Help to rename files Hilton Excel Worksheet Functions 7 July 7th 07 03:51 AM
Rename Multiple Excel Workbooks based on cell contents Scott Campbell[_2_] Excel Discussion (Misc queries) 4 April 24th 07 10:00 PM
How to create a copy of a folder having five files in it, & rename Matthews Excel Worksheet Functions 1 November 7th 06 03:42 PM
How do I rename multiple sheets at one time in Excel? Navigator Excel Worksheet Functions 1 July 25th 06 07:51 PM
Does XL2K have "hard hyphens" (non-break hyphens)? StargateFan Excel Discussion (Misc queries) 0 January 29th 05 01:36 PM


All times are GMT +1. The time now is 05:17 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"