Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default V2003 Macro not working in V2007

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,


Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default V2003 Macro not working in V2007

The flakey .filesearch was removed in xl2007.

Ron de Bruin shows a couple of alternatives:
http://www.rondebruin.nl/copy3.htm
and
http://www.rondebruin.nl/fso.htm

JMay-Rke wrote:

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,

Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default V2003 Macro not working in V2007

WOW, this is a bit "over-the-top" confusing/new to me. I've been googling
the last 24 hrs - havibg seen and previoulsy studied Ron's Code. Still lost;
Being New to 2007 adds to my dilemma.

"Dave Peterson" wrote:

The flakey .filesearch was removed in xl2007.

Ron de Bruin shows a couple of alternatives:
http://www.rondebruin.nl/copy3.htm
and
http://www.rondebruin.nl/fso.htm

JMay-Rke wrote:

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,

Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default V2003 Macro not working in V2007

Try downloading one of the workbooks that Ron provides. Maybe you can step
through the code to understand it.

JMay-Rke wrote:

WOW, this is a bit "over-the-top" confusing/new to me. I've been googling
the last 24 hrs - havibg seen and previoulsy studied Ron's Code. Still lost;
Being New to 2007 adds to my dilemma.

"Dave Peterson" wrote:

The flakey .filesearch was removed in xl2007.

Ron de Bruin shows a couple of alternatives:
http://www.rondebruin.nl/copy3.htm
and
http://www.rondebruin.nl/fso.htm

JMay-Rke wrote:

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,

Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default V2003 Macro not working in V2007

Dave;
I'm afraid I did - I ran it - got a disaster from it. Gonna have to put
this on the shelf until I have several days to "understand". Thanks,
Jim

"Dave Peterson" wrote:

Try downloading one of the workbooks that Ron provides. Maybe you can step
through the code to understand it.

JMay-Rke wrote:

WOW, this is a bit "over-the-top" confusing/new to me. I've been googling
the last 24 hrs - havibg seen and previoulsy studied Ron's Code. Still lost;
Being New to 2007 adds to my dilemma.

"Dave Peterson" wrote:

The flakey .filesearch was removed in xl2007.

Ron de Bruin shows a couple of alternatives:
http://www.rondebruin.nl/copy3.htm
and
http://www.rondebruin.nl/fso.htm

JMay-Rke wrote:

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,

Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default V2003 Macro not working in V2007

Didn't take quiet a few days, but my new code I have as follows: It is working
intermittanly, that is the results are both **right* and **wrong**. Do you
see anything drastically wrong?
Thanks,
Jim


Sub ListFiles()
Dim sFol As String
Dim fso As Object, fl As Object
Dim fld As Object
Dim wb As Workbook
Dim Fcount As Long
sFol = ActiveSheet.Range("D1").Value
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(sFol)
s = Range("B3").Value
Range(Cells(4, 2), Cells(Rows.Count, 2)).ClearContents
s2 = "*" & s & "*.*"
Fcount = 0
I = 0
For Each fl In fld.Files
If fl.Name Like s2 Then
Fcount = Fcount + 1
End If
' End If
Next
MsgBox "There were " & Fcount & " file(s) found."
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For Each fl In fld.Files
If fl.Name Like s2 Then
I = I + 1
Set wb = Workbooks.Open(fl.Path)
ThisWorkbook.ActiveSheet.Cells(I + 3, 2).Value = Mid(fl, 38, 256)
wb.Close False
End If
' End If
Next
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
' MsgBox "How does it look?"
End Sub

"JMay-Rke" wrote:

Dave;
I'm afraid I did - I ran it - got a disaster from it. Gonna have to put
this on the shelf until I have several days to "understand". Thanks,
Jim

"Dave Peterson" wrote:

Try downloading one of the workbooks that Ron provides. Maybe you can step
through the code to understand it.

JMay-Rke wrote:

WOW, this is a bit "over-the-top" confusing/new to me. I've been googling
the last 24 hrs - havibg seen and previoulsy studied Ron's Code. Still lost;
Being New to 2007 adds to my dilemma.

"Dave Peterson" wrote:

The flakey .filesearch was removed in xl2007.

Ron de Bruin shows a couple of alternatives:
http://www.rondebruin.nl/copy3.htm
and
http://www.rondebruin.nl/fso.htm

JMay-Rke wrote:

This Code Worked PERFECT in V2003 - I'm having a time getting the equivalent
to work for me in V2007. Can someone assist me?
TIA,

Sub ListFiles()
Dim s As String
Dim sfolder As String
sfolder = Range("D1").Value
s = Range("B3").Value
Range("B4:B65536").ClearContents
s2 = "*" & s & "*.*"
With Application.FileSearch
.NewSearch
.LookIn = sfolder
.SearchSubFolders = True
.Filename = s2
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
ActiveSheet.Cells(i + 3, 2).Value = _
Mid(.FoundFiles(i), 64, 256)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub

--

Dave Peterson


--

Dave Peterson

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
Unable to read .dat excel files in v2003 dsears Excel Discussion (Misc queries) 9 October 27th 09 02:13 PM
excel spreadsheets freeze in v2007 (xp pro SP3) stumped-in-excel[_2_] Excel Discussion (Misc queries) 2 April 3rd 09 04:39 PM
No Save Prompt dialog box when existing (V2003) Mike Excel Discussion (Misc queries) 1 November 28th 07 05:27 PM
Mail Merge default directory v2003 leaftye Setting up and Configuration of Excel 0 June 16th 05 08:45 PM
Mail Merge default directory v2003 leaftye Setting up and Configuration of Excel 0 June 16th 05 03:43 PM


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