Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help to rename files | Excel Worksheet Functions | |||
Rename Multiple Excel Workbooks based on cell contents | Excel Discussion (Misc queries) | |||
How to create a copy of a folder having five files in it, & rename | Excel Worksheet Functions | |||
How do I rename multiple sheets at one time in Excel? | Excel Worksheet Functions | |||
Does XL2K have "hard hyphens" (non-break hyphens)? | Excel Discussion (Misc queries) |