[Libreoffice-bugs] [Bug 118241] New: FILEOPEN XLSX Basic code with CreateObject("Scripting.FileSystemObject") and “For Each ” loop does not work

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Tue Jun 19 15:36:30 UTC 2018


https://bugs.documentfoundation.org/show_bug.cgi?id=118241

            Bug ID: 118241
           Summary: FILEOPEN XLSX Basic code with
                    CreateObject("Scripting.FileSystemObject") and “For
                    Each ” loop does not work
           Product: LibreOffice
           Version: 6.2.0.0.alpha0+ Master
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: BASIC
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: kelemeng at ubuntu.com

Created attachment 142919
  --> https://bugs.documentfoundation.org/attachment.cgi?id=142919&action=edit
Example file from Excel

If we try to run the macro in the attached file, the file listing For Each loop
will not run.

Steps to reproduce:
1. Create a new spreadsheet with Microsoft Excel 2016/2013
2. Open the Visual Basic window
3. Add a new Module to your VBAProject
4. Use this simple code:
Sub fileoperation()
Dim fso As Object
Dim dir As Object
Dim Files As Object
Dim File As Object
Dim i As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
If Range("D2") = "" Then
x = Range("B3").CurrentRegion.Rows.Count + 1
sx = Cells(x, 2).Address(False, False)
Range("A3:" + sx + "").ClearContents
MsgBox "Empty data"
Else
s = Range("B3").CurrentRegion.Rows.Count + 1
st = Cells(s, 2).Address(False, False)
Range("A3:" + st + "").ClearContents
a = Range("D2")
If fso.FolderExists(a) = False Then
MsgBox "Folder doesn't exists"
Else
Set dir = fso.GetFolder(a)
Set Files = dir.Files
i = 2
For Each File In Files //This loop does not work in LibreOffice.
Cells(i + 1, 1).Value = File.Name
Cells(i + 1, 2).Value = File.Path
i = i + 1
Next File
MsgBox "Found " & Files.Count & " files."
End If
End If
End Sub

5. Write a Directory path (which contains files) to the “D2” cell. Run the
macro.
6. Save the file as *.xlsm
7. Open the file with LibreOffice Calc. Run the macro.

Actual results: The macro is executed but the “For Each File In Files” was
ignored. So the files name and paths were not listed.


Expected results:
This simple basic code run perfectly in Microsoft Excel, even if I reopen the
file with Microsoft Excel, after I saved in LibreOffice Calc. This simple macro
should run perfectly in LibreOffice Calc.


Version: 6.2.0.0.alpha0+
Build ID: c3e552ac25be001a623469c549ee8d0719b98133
CPU threads: 1; OS: Windows 6.1; UI render: default; 
TinderBox: Win-x86 at 42, Branch:master, Time: 2018-06-13_23:01:19
Locale: hu-HU (hu_HU); Calc: group threaded

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20180619/94eca483/attachment-0001.html>


More information about the Libreoffice-bugs mailing list