1
我已經做了互聯網上的廣泛搜索,但仍然沒能找到解決方案。有趣的是,我的代碼之前工作。我使用與VBScript代碼html頁面,打開使用IE 9.奇怪的VBScript錯誤「objFolder」
我的代碼是下面:
29: Function TraverseDirectory(objFolder, searchTerm, outFile)
30: if objFolder.SubFolders.Count > 0 then <-- ERROR shown in this line: Object required: 'objFolder'
31: MsgBox objFolder.SubFolders.Count <-- This message is shown without an issue
32: Set fc = objFolder.SubFolders
33: For Each f1 in fc
34: ProcessFolder f1, searchTerm, outFile
35: TraverseDirectory f1, searchTerm, outFile
36: Next
37: else
38: ProcessFolder objFolder, searchTerm, outFile
39: end if
40: End Function
我顯示該錯誤在管線30:所需的對象 'objFolder'
我加第31行的消息框已到達,輸出帶有許多子文件夾的消息框。如果問題在第30行實際上是,它永遠不會達到31行。如果我徹底清除線31(其中帶有一個消息框),我還是得到線相同的錯誤30
上面我的函數被調用採用以下方式:
Set objFolder = objFSO.GetFolder("C:\Test")
TraverseDirectory objFolder, str, outFile
該文件夾存在並且檢索時沒有問題。不知道發生了什麼事。有人可以解釋這個問題嗎?
我不能重現該問題,但*威力*是一個範圍問題與'objFolder'變量。你可以通過改變'objFolder'來測試這個功能,例如'objFolderInsideFunction'嗎? – langstrom
第29行到第30行之間和第一個「TraverseDirectory」之前的'MSGBOX VarType(objFolder)&vbTab&TypeName(objFolder)'的輸出是什麼? – JosefZ
輸出是「8文件夾」後跟「9無」 – ElenaDBA