Error from Excel 2003 to 2007

YeshyTiger

New Member
Joined
Oct 21, 2008
Messages
23
Hello,

My company had been using 2003 when I created a very large macro looped through files checking each one to a certain criteria. Now that we have upgraded to 2007, it does not recognize at least the first part of the macro that sets up the loop. Could anyone tell me why it is not recognizing the loop when it used to in 2003?

Code:
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Dim error As Integer
Dim psswrd As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

Set wbCodeBook = ThisWorkbook
    With Application.FileSearch
        .NewSearch
         'Change path to suit
        .LookIn = "C:\Documents and Settings\JG\Desktop\PMP Input Folder"
        .FileType = msoFileTypeExcelWorkbooks
        .Filename = "*.xls"
        
            If .Execute > 0 Then 'Workbooks in folder
                For lCount = 1 To .FoundFiles.Count 'Loop through all.
                 'Open Workbook x and Set a Workbook variable to it
                 Set wbResults = Workbooks.Open(.FoundFiles(lCount))
                 
                .Select
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hmmm, I'm trying to understand the post in the link you gave me. Here is the template code I have now for just the loop:

Code:
[B]Sub RunCodeOnAllXLSFiles()[/B]

Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Application.EnableEvents = False

On Error Resume Next


Set wbCodeBook = ThisWorkbook

    With Application.FileSearch
        .NewSearch

         'Change path to suit

        .LookIn = "C:\MyDocuments\TestResults"

        .FileType = msoFileTypeExcelWorkbooks

        '.Filename = "Book*.xls"
      
            If .Execute > 0 Then 'Workbooks in folder

                For lCount = 1 To .FoundFiles.Count 'Loop through all.

                 'Open Workbook x and Set a Workbook variable to it

                 Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)



                [B] 'DO YOUR CODE HERE[/B]


                 wbResults.Close SaveChanges:=True

                 Next lCount

            End If

    End With

    On Error GoTo 0

    Application.ScreenUpdating = True

    Application.DisplayAlerts = True

    Application.EnableEvents = True


[B]End Sub[/B]


And what it should become is?

Code:
Dim myDir As String, fn As String
myDir = strPath & "\"
fn = Dir(myDir & "*.xls")
Do While fn <> ""
    'Do Code Here
Loop
 
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,109
Members
449,205
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top