我需要找出每個excel表單下一個文件夾中的行數.Google搜索顯示下面的腳本工作正常..但對vb,我無法解決它。腳本containe'Wscript object.I認爲這也適用於此對象以及腳本查找特定文件夾下excel下的行數使用vb
事情是在「c:\ temp」下,我有100個Excel表(.xls) 。需要找出每個文件中的行數。從VB專家幫助需要
Dim objFSO, strFolder, objFolder, objFile, objExcel, objSheet, objRange, objRows As Object
Dim strExtension As String
Dim V_FilePath As String = " "
' Specify folder.
strFolder = "c:\\temp" -----
objExcel = CreateObject("Excel.Application")
' Enumerate files in the folder.
objFSO = CreateObject("Scripting.FileSystemObject")
objFolder = objFSO.GetFolder(strFolder)
For Each objFile In objFolder.Files
' Select only Excel spreadsheet file.
strExtension = objFSO.GetExtensionName(objFile.Path)
If (strExtension = "xls") Or (strExtension = "xlsx") Then
' Open each spreadsheet and count the number of rows.
objExcel.Workbooks.Open(objFile.Path)
objSheet = objExcel.ActiveWorkbook.Worksheets(1)
objRange = objSheet.UsedRange
objRows = objRange.Rows
' Display spreadsheet name and the number of rows.
MsgBox(objExcel.ActiveWorkbook + CStr(objRows.Count))
''Wscript.Echo(objFile.Path & " (" & objRows.Count & ")")
' Close the spreadsheet.
objExcel.ActiveWorkbook.Close()
End If
Next
' Clean up.
objExcel.Application.Quit()
Dts.TaskResult = ScriptResults.Success
End Sub
你試過嗎?你遇到了什麼錯誤 ? – rags
這是工作。在這個意義上,我正在獲得的數額。但我需要每個文件的名稱和數量,所以我怎麼能得到這些細節 – user1254579