Runtime error 424 Object required

Joe9238

Board Regular
Joined
Jul 14, 2017
Messages
67
Hi all,
I have this line of code that gathers data from specified files with certain names in a list. I think I have everything I need but it comes up with
Code:
Runtime error 424 Object required
and highlights
Code:
for each objfile in objfiles
The full thing is here
Code:
Sub Test()
Dim sFolder As String


    Application.ScreenUpdating = True
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = Application.DefaultFilePath & "\"
        .Title = "Please select a folder..."
        .Show
        If .SelectedItems.Count > 0 Then
            sFolder = .SelectedItems(1) & "\"
        Else
            Exit Sub
        End If
    End With
    
    Call Consolidate(sFolder, ThisWorkbook)
End Sub
Private Sub Consolidate(sFolder As String, wbMaster As Workbook)
    Dim wbTarget As Workbook
    Dim objFso As Object
    Dim ary(3) As Variant
    Dim lRow As Long
    Dim objFiles As Object
    Dim objFile As Object
    
Dim CodeNames As Variant, i As Long
CodeNames = Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row)
For Each objFile In objFiles
For i = 1 To UBound(CodeNames, 1)
If objFile.Name Like "*" & CodeNames(i, 1) & "*" Then
'get data from the file
Exit For
End If
Next i
Next objFile


End Sub

Any help is appreciated
Thanks in advance
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
You'll need to first create an instance of the FileSystemObject using the CreateObject method. So you should have something like this...

Code:
[FONT=Calibri][COLOR=darkblue]Set[/COLOR] objFso = CreateObject("Scripting.FileSystemObject")
[COLOR=darkblue]Set[/COLOR] objFiles = objFso.GetFolder(sFolder).Files

[COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] objFile [COLOR=darkblue]In[/COLOR] objFiles
    [COLOR=green]'etc[/COLOR]
    '
    '
[COLOR=darkblue]Next[/COLOR] objFile[/FONT]
 
Upvote 0
That's great! It has stopped the error. Would you happen to know how to get the data from the files listed? I'm still stuck on that part. Thanks for the help so far.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,233
Members
449,092
Latest member
SCleaveland

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