Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default amend this routine to use something other than Application.FileSearch

I'd like to amend this routine to use something other than
Application.FileSearch.

Any thoughts would be most welcome.

Sub RenameJPGs()

Dim oldname As String
Dim newname As String
Dim fname As String
Dim pname As String
Dim i As Integer
Dim d As Variant
fname = "*.jpg" 'filename
pname = "C:\Documents and settings\user\my documents\pics\" 'folder to
use

With Application.FileSearch
.NewSearch
.LookIn = pname
.SearchSubFolders = False
.Filename = fname 'check to see if any files match the fname
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
d = Format(Date, "dddd")
oldname = .FoundFiles(i)
newname = pname & d & i & ".jpg"
Name oldname As newname
Next
End If
End With


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default amend this routine to use something other than Application.FileSearch

Dim oFSO

Sub RenameJPGs()
Const pname As String = _
"C:\Documents and settings\user\my documents\pics\" 'folder to use

Set oFSO = CreateObject("Scripting.FileSystemObject")

selectFiles pName

Set oFSO = Nothing

End Sub


'---------------------------------------------------------------------------
Sub selectFiles(sPath)
'---------------------------------------------------------------------------
Dim Folder As Object
Dim Files As Object
Dim file As Object
Dim fldr
Dim oldname As String
Dim newname As String
Dim fname As String
Dim i As Integer
Dim d As Variant

Set Folder = oFSO.GetFolder(sPath)

For Each fldr In Folder.Subfolders
selectFiles fldr.Path
Next fldr

For Each file In Folder.Files
If file.Type = "JPEG Image" Then
i = i + 1
oldname = file.Path
newname = sPath & "\" & Format(Date, "dddd") & i & ".jpg"
Name oldname As newname
End If
Next file

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Lucas Budlong" wrote in message
...
I'd like to amend this routine to use something other than
Application.FileSearch.

Any thoughts would be most welcome.

Sub RenameJPGs()

Dim oldname As String
Dim newname As String
Dim fname As String
Dim pname As String
Dim i As Integer
Dim d As Variant
fname = "*.jpg" 'filename
pname = "C:\Documents and settings\user\my documents\pics\" 'folder to
use

With Application.FileSearch
.NewSearch
.LookIn = pname
.SearchSubFolders = False
.Filename = fname 'check to see if any files match the fname
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
d = Format(Date, "dddd")
oldname = .FoundFiles(i)
newname = pname & d & i & ".jpg"
Name oldname As newname
Next
End If
End With


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
Application.FileSearch Cleberton(Brazilian) Excel Discussion (Misc queries) 2 October 26th 09 01:21 PM
Help with Application.FileSearch method Roy Harrill Excel Programming 4 August 1st 05 12:56 AM
Application.FileSearch is not working?? alondon Excel Programming 5 January 18th 05 03:12 AM
Slow FileSearch Routine stratuser Excel Programming 0 May 14th 04 02:56 PM
VBA Application.FileSearch Roger Frye Excel Programming 0 March 5th 04 04:07 AM


All times are GMT +1. The time now is 02:17 PM.

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"