2014-02-11 91 views
0

我想通过发送邮件将脚本上传到Flickr上。完整的脚本可以在这里找到:http://pastebin.com/6pQFMZmkvbscript,递归设置对象

我选择使用Excel作为数据库来记住之前上传的内容;对于我需要在电子表格中搜索的每个文件,如果它已经上传。这是通过将变量objCell设置为find函数的结果来完成的。
这工作第一次,但我设置objCell我第二次得到的错误:runtime error: Object variable not set

代码的相关部分如下:

Sub ShowSubFolders(Folder) 
     For Each Subfolder in Folder.SubFolders 
     wscript.echo "VOLGENDE FOLDER" 
     wscript.echo "" 

     Set objFolder = objFSO.GetFolder(Subfolder.Path) 
     Set colFiles = objFolder.Files 
     For Each objFile in colFiles 
      if soort.Exists(UCase(Mid(objFile.Name, InStrRev(objFile.Name,".") + 1))) Then 
       strSearchTerm = objFile.Name & objFile.Size & objFile.DateLastModified 

       msgbox strSearchTerm & " ; " & objCell & " ; " & xlFormulas & " ; " & xlPart & " ; " & xlByRows & " ; " & xlNext & " ; " & boolMatchCase 
       'THE LINE UNDER HERE IS THE PROBLEM 
       Set objCell = objWorkSheet.Cells.Find(strSearchTerm, objCell, xlFormulas,xlPart, xlByRows, xlNext, boolMatchCase) 

       If Not objCell Is Nothing Then 
        'I found it!, don't upload... 
        objCell = Nothing 
       Else 
        'not fout; upload 
        temp = upload(subfolder.path & "\" & objFile.Name) 
        wscript.echo String(6-len(introw)," ") & intRow & " " & Subfolder.Path & " " & objFile.Name & " ; " & Mid(Subfolder.Path, InStrRev(Subfolder.Path, "\")+1) & " ; " & UCase(Mid(objFile.Name, InStrRev(objFile.Name,".") + 1)) & " " & objFile.Size 
        if temp then 
         objExcel.Cells(intRow, 2).Value = strSearchTerm 
         objExcel.Cells(intRow, 1).value = Now() 
        Else 
         objExcel.Cells(intRow, 2).Value = objFile.Name 
         objExcel.Cells(intRow, 1).value = "upload failed" 
        End if 
        intRow = intRow + 1 
       End if 
      Else 
       wscript.echo objFile.name & ": " & Mid(objFile.Name, InStrRev(objFile.Name,".") + 1) & " is niet in type" 
      End if 
     Next 
     ShowSubFolders Subfolder 
    Next 
    End Sub 

我不知道我可以使用一个简单的文本文件来跟踪上传;但我已经决定使用excel;后来我做了扩展脚本的计划,因为这个Excel会很方便。

回答

0

您需要Set分配对象(没有什么是一个对象!)给一个变量:

objCell = Nothing 

==>

Set objCell = Nothing 
+0

AAAAH,这是如此顺理成章。今晚会尝试 – Brtrnd