Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default What is wrong with this code?

This code is suppose to move and rename all files to a different
directory with todays date in the format of "mmyydd_" in the front of
each file. When the code runs it find all my files but the files are
not renamed or moved. What am I doing wrong?

Thanks
Steve

****CODE START HERE****

Sub MSIToIMDS()
Application.ScreenUpdating = False


Dim OldName As String
Dim NewName As String
Dim x As String
Dim i As Integer
'set file path

Oldpath = "C:\MSIReportNameConvert\MSI_Input\"
Newpath = "C:\MSIReportNameConvert\IMDS_Output\"


With Application.FileSearch
.NewSearch
.LookIn = Oldpath
.SearchSubFolders = False 'True
.MatchTextExactly = False


.Filename = "*.*"
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
On Error Resume Next
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)


xconvention = Format(Date, "MMDDYY_")
NewName = Newpath & xconvention & OldName
Name OldName As NewName
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default What is wrong with this code?

If your new path is using an existin directory then you could use the Move
method to put the file there after you rename it. Otherwise, you would need
to use MkDir to set up the new directory and then move the file. I don't
think you can reassign directiories by renaming only.

"Steve" wrote:

This code is suppose to move and rename all files to a different
directory with todays date in the format of "mmyydd_" in the front of
each file. When the code runs it find all my files but the files are
not renamed or moved. What am I doing wrong?

Thanks
Steve

****CODE START HERE****

Sub MSIToIMDS()
Application.ScreenUpdating = False


Dim OldName As String
Dim NewName As String
Dim x As String
Dim i As Integer
'set file path

Oldpath = "C:\MSIReportNameConvert\MSI_Input\"
Newpath = "C:\MSIReportNameConvert\IMDS_Output\"


With Application.FileSearch
.NewSearch
.LookIn = Oldpath
.SearchSubFolders = False 'True
.MatchTextExactly = False


.Filename = "*.*"
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
On Error Resume Next
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)


xconvention = Format(Date, "MMDDYY_")
NewName = Newpath & xconvention & OldName
Name OldName As NewName
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 221
Default What is wrong with this code?

G'day Steve

Try this

Dim OldName As String
Dim NewName As String
Dim x As String
Dim i As Integer
Dim FileYes As Integer
Dim FileNo As Integer

With Application
..ScreenUpdating = False
..EnableEvents = False
End With

Set Oldpath = "C:\MSIReportNameConvert\MSI_Input\"
Set Newpath = "C:\MSIReportNameConvert\IMDS_Output\"

With Application.FileSearch
.NewSearch
.LookIn = Oldpath
.SearchSubFolders = False 'True
.MatchTextExactly = False
.Filename = "*.*"
If .Execute(msoSortOrderDescending) 0 Then
FileYes = MsgBox ("There were " & .FoundFiles.Count & " file(s)
found.",vbOKOnly)
On Error Resume Next
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)

xconvention = Format(Date, "MMDDYY_")
NewName = Newpath & xconvention & OldName
Name OldName As NewName
Next i
Else
FileNo = MsgBox ("There were no files found.",vbOKOnly)
End If
End With

With Application
..ScreenUpdating = False
..EnableEvents = False
End With

End Sub

HTH
Mark.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default What is wrong with this code?

Sub MSIToIMDS()
Application.ScreenUpdating = False
Dim OldPath As String
Dim NewPath As String
Dim OldName As String
Dim NewName As String
Dim x As String
Dim i As Integer
Dim xconvention
'set file path

OldPath = "C:\test" '"C:\MSIReportNameConvert\MSI_Input\"
NewPath = "C:\MSIReportNameConvert\IMDS_Output\"

With Application.FileSearch
.NewSearch
.LookIn = OldPath
.SearchSubFolders = False 'True
.MatchTextExactly = False

.Filename = "*.*"
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
On Error Resume Next
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)

xconvention = Format(Date, "MMDDYY_")
NewName = NewPath & xconvention & Mid(OldName,
InStrRev(OldName, "\") + 1)
Name OldName As NewName
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub


--
__________________________________
HTH

Bob

"Steve" wrote in message
...
This code is suppose to move and rename all files to a different
directory with todays date in the format of "mmyydd_" in the front of
each file. When the code runs it find all my files but the files are
not renamed or moved. What am I doing wrong?

Thanks
Steve

****CODE START HERE****

Sub MSIToIMDS()
Application.ScreenUpdating = False


Dim OldName As String
Dim NewName As String
Dim x As String
Dim i As Integer
'set file path

Oldpath = "C:\MSIReportNameConvert\MSI_Input\"
Newpath = "C:\MSIReportNameConvert\IMDS_Output\"


With Application.FileSearch
.NewSearch
.LookIn = Oldpath
.SearchSubFolders = False 'True
.MatchTextExactly = False


.Filename = "*.*"
If .Execute(msoSortOrderDescending) 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
On Error Resume Next
For i = 1 To .FoundFiles.Count
OldName = .FoundFiles(i)


xconvention = Format(Date, "MMDDYY_")
NewName = Newpath & xconvention & OldName
Name OldName As NewName
Next i
Else
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub



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
What is wrong with this code ?? cgnotrom Excel Programming 5 May 31st 08 03:39 AM
What's wrong with my code? Thanks Exceller Excel Programming 4 April 24th 07 10:40 PM
What is wrong with this code? Jan Excel Programming 4 June 14th 05 06:48 PM
Can someone tell me what's wrong with this code please? malycom Excel Programming 4 June 3rd 04 03:26 PM
Is something wrong with the code Patrick Molloy[_3_] Excel Programming 1 July 15th 03 08:28 AM


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