1
我正在寫一個VBScript函數,它看起來是這樣的:列出在VBScript中返回的對象
Public Function fnGetXLSFileCount()
Dim fso, src, folder, file, fileList
Set fileList = CreateObject("System.Collections.ArrayList")
Set fso = CreateObject("Scripting.FileSystemObject")
src = "\\myserver\myfolder"
Set folder = fso.GetFolder(src)
For Each file In folder.files
If LCase(fso.GetExtensionName(file)) = "xlsx" Then
fileList.Add file.name
End If
Next
Set fnGetXLSFileCount = fileList
End Function
正如你可以看到我創建一個ArrayList,然後加入存在於Excel的文件,所有名字指定的文件夾。
然後我調用這個函數,並使用Set運算符來指定我期待的對象被返回。
Set XLSFileList = fnGetXLSFileCount
當我檢查對象的計數,它似乎是正確的。 當我試圖拉出名字時,那裏什麼也沒有。我在這裏做錯了什麼?
For each file in XLSFileList
name = file.Item(0)
Next
是的,()在那裏是可選的。 –