LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Rename files with variable names

I would like to find code that would take a variable out of filenames in a
specific location.

For example, here are my file names:
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_AgtSum_060206_142704.dl t"
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_GrpCall_060206_142715.d lt"
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_GrpSum_060206_142520.dl t"
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_GrpTime_060206_142722.d lt"

I need to remove the uderscore and last 6 numbers from the file name to read:
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_AgtSum_060206_142704.dl t"
becomes
"G:\A F S\Monthly Reports\HiPath\CS\MonthlyC_AgtSum_060206.dlt"

I need to do this because I can't loop through other code to open and modify
the files because the file names are variable.

I've tried the following code:
Do
If FOLDERLOOP = 1 Then FILENAMEFOLDER = "CS\MONTHLYC_AGTSUM_"
If FOLDERLOOP = 2 Then FILENAMEFOLDER = "CS\MONTHLYC_GRPCALL_"
If FOLDERLOOP = 3 Then FILENAMEFOLDER = "CS\MONTHLYC_GRPSUM_"
If FOLDERLOOP = 4 Then FILENAMEFOLDER = "CS\MONTHLYC_GRPTIME_"

If FOLDERLOOP = 5 Then Exit Do

OLDFILENAME = "G:\A F S\MONTHLY REPORTS\HIPATH\" & FILENAMEFOLDER &
RPTRUNDATE & "_*.dlt"
NEWFILENAME = "G:\A F S\MONTHLY REPORTS\HIPATH\" & FILENAMEFOLDER &
RPTRUNDATE & ".dlt"

SHELLCOMMAND = "Command.com /c ren " & OLDFILENAME & " " & NEWFILENAME

Application.Shell (SHELLCOMMAND)

FOLDERLOOP = FOLDERLOOP + 1

Loop Until FOLDERLOOP = 5

I've tried to also use:
Application.Shell (Command.com /c ren " & OLDFILENAME & " " & NEWFILENAME)

So I've come to the conclusion that I need to get rid of the variable in the
file name so I can use true file names.

How can I do this?

THX!
 
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
rename category names rename category names Charts and Charting in Excel 3 December 17th 09 10:51 AM
rename all cell names but keep the formula steve alcock Excel Discussion (Misc queries) 4 March 3rd 07 01:31 PM
Rename Defined Names Sige Excel Worksheet Functions 3 January 13th 06 05:44 PM
Rename Multiple Sheets from a List of Available Names prkhan56 Excel Programming 5 April 4th 05 06:07 PM
VBA: rename a variable qwerqtzui Excel Programming 3 November 5th 03 05:03 PM


All times are GMT +1. The time now is 01:50 AM.

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

About Us

"It's about Microsoft Excel"