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: 211
Default Renaming Files

Hi

I have a collection of randomly titled excel files in a folder called Raw1.
The only thing these files have in common is that on a sheet called summary,
in cell D3, there is a random text string containing a random number. The
code below is my unsuccessful stab at cycling through these files,
identifying the random number within the random text string on D3, then
saving the file with the identified number to the target destination file.
Look at the following code. It creates the destination folder and says the
task has been completed (done), but no files are converted and placed in the
destination folder. I'm at my wits end! I run Excel 2003 on XP pro.

Thanks...


Sub FileNamer()
Dim FilePath As String
Dim FileName As String
Dim aStart As Integer
Dim DestPath As String

Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

'EDIT TO MATCH PATH THAT CONTAINS YOUR FILES
FilePath$ = "C:\Documents and Settings\cartwrig\Desktop\Raw1\"

'EDIT TO MATCH FOLDER TO HOLD YOUR NEW FILES (MUST BE DIFFERENT FROM Source
Dir)
DestPath$ = "C:\tested\"
If Dir(DestPath$, vbDirectory) = "" Then MkDir (DestPath$)

FileName$ = Dir(FilePath$ & "*.xls")
Do Until FileName$ = ""
Workbooks.Open FilePath$ & FileName$, 0, 1

a$ = Workbooks(FileName$).Sheets("Summary").Range("D3") .Value

For x = 1 To Len(a$)
If IsNumeric(Mid(a$, x, 1)) = True Then
aStart = x
a$ = Right(a$, Len(a$) - aStart + 1)
a$ = Trim(Left(a$, InStr(a$, " ")))
GoTo NumFound
End If
Next
NumFound:
ActiveWorkbook.SaveAs DestPath$ & a$ & ".xls"
ActiveWorkbook.Close 0


FileName$ = Dir

Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "done"
End Sub


 
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
Renaming Files Gordon[_2_] Excel Programming 20 June 25th 06 08:25 AM
Renaming files Gordon[_2_] Excel Programming 1 June 24th 06 11:39 AM
Renaming Files Bear Excel Discussion (Misc queries) 2 December 5th 05 09:02 PM
Renaming Files: Take 2 Dominique Feteau Excel Programming 4 July 14th 04 04:27 PM
Renaming files Dana Wilson Excel Programming 2 October 29th 03 05:34 PM


All times are GMT +1. The time now is 04:26 PM.

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"