Sub list_iteration below runs just fine.
Sub ListFilesFSO() below throws the following Error at the For Each statement:
Inadmissible value or data type. Data type mismatch.
Why?
LO 7.0.2.2, Windows10 64bit
(ListFilesFSO was copied from blog Get list of Excel files in a folder using VBA - Stack Overflow)
In this sub the For Each loop runs fine:
Sub list_iteration
cutlery = Array("fork", "knife", "spoon")
For Each item in cutlery
Print item
Next ' item
End Sub
In this sub the For Each loop throws an Error:
Public Sub ListFilesFSO(ByVal sPath As String)
Dim oFSO As Object
Dim oFolder As Object
Dim oFile As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder("C:\Users\user1\Desktop")
For Each oFile In oFolder.Files
Print oFile.Name
Next oFile
Set oFile = Nothing
Set oFolder = Nothing
Set oFSO = Nothing
End Sub
Any insight is welcome.