0

我有 2 个文件夹textFilesexcelFiles,它们具有相同的文件名但具有不同的扩展名(对于 textFiles = .txt 和 excelFiles = .xlsx),我编写了一个代码,以查找 textFiles 中的文件是否在 excelFiles 中不存在来调用创建它的函数。

Sub LookForNew()
Dim dTxt As String
Set fso = CreateObject("Scripting.FileSystemObject")
Set filsTxt = fso.GetFolder("C:\txtFiles").Files
Set filsExcel = fso.GetFolder("C:\excelFiles").Files
Set oFileExcel = CreateObject("Scripting.Dictionary")
Set tFileExl = CreateObject("Scripting.Dictionary")
Set oFileExl = CreateObject("Scripting.Dictionary")
For Each fil In filsTxt
  dTxt = fil.Name
    For Each exl In filsExcel
       oFileExcel = exl.Name
       oFileExl = Split(oFileExcel, ".")
       tFileExl = oFileExl(0)
        Next exl
        If Not (tFileExl.Exists(dTxt)) Then
           ' Call function
        Else
        MsgBox "No more files to convert"
        End If
Next fil
Set fso = Nothing

结束子

但是我的代码中的“oFileExcel”字段不返回字典,而是返回字符串帮助 plz

4

1 回答 1

0

您不能像以前那样分配值oFileExcel = exl.Name,您需要使用oFileExcel.Add = exl.Name.

看看字典的文档:

Dim d                   'Create a variable
Set d = CreateObject(Scripting.Dictionary)
d.Add "a", "Athens"     'Add some keys and items
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
...
于 2016-06-16T10:10:31.823 回答