Ask Your Question
0

For Each Loop, Error: Data type mismatch

asked 2021-01-08 01:40:39 +0100

Phrance QueTara gravatar image

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 https://stackoverflow.com/questions/3...)

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-01-08 04:15:37 +0100

Ratslinger gravatar image

Hello,

You will find it best to avoid using VBA code in LO, especially in Base, as much needs to be re-written using LO API.

For Base this may help -> Access2Base.

For Star Basic, here is a post with code placing the listing in a Calc document -> How to get file names from a folder

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2021-01-08 01:40:39 +0100

Seen: 23 times

Last updated: Jan 08