我是VBscript的新手,我正在編寫一個簡單的腳本,用於在給定文件夾位置中的幾千個csv文件中更改幾個單元格。我有一個很好的開始,似乎所有的工作,除了當我運行腳本(從一個只調用腳本的.bat文件),它只改變和移動3-8個文件。它改變的文件數量是隨機的,不像它總是改變5個文件或其他東西。我不確定代碼中出現了什麼問題,爲什麼它不會編輯和移動每個文件,並且每次只能執行一次,這是我迄今爲止所提供的任何幫助提前感謝:VB腳本不會遍歷給定文件夾中的每個文件
Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set colFiles = ObjFSO.GetFolder("C:\Users\xxx\BadCSVs").Files
Set xl = CreateObject("Excel.Application")
For Each objFile in colFiles
If LCase(objFSO.GetExtensionName(objFile)) = "csv" Then
Set wb = xl.Workbooks.Open(objFile)
Set sht = xl.ActiveSheet
If(sht.Cells(1,11) <> "") Then
sht.Cells(1,8) = sht.Cells(1,8) & sht.Cells(1,9)
sht.Cells(1,9) = sht.Cells(1,10)
sht.Cells(1,10) = sht.Cells(1,11)
sht.Cells(1,11) = Null
wb.Save
wb.Close True
Else
'if file is opened up and has only 10 columns of data, then it makes no changes, then closes it.
wb.Close
End If
End If
Next
xl.Quit
VB.NET IsNot vba並且也VB.NET IsNot VBScript。 – Plutonix
On Error Resume Next可能會掩蓋可能解釋您的不一致行爲的錯誤。 –