VBScript打开文件夹将csv转换为xls

任何人都可以解释为什么这不起作用,它抛出一个错误说:

行:14字符:1错误:对象需要:'[string:“H:\ VBS”]'代码:800A01A8

Const xlDelimited = 1 Const xlNormal = -4143 Set Excel = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") Dim Excel dim objShell dim objFolder Dim fileLocation set objShell = CreateObject("shell.application") set objFolder = objshell.BrowseForFolder(0, "Select File Location", 1, "H:\") set fileLocation = CStr(objFolder.self.path) Set Excel = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") folderDestination = InputBox("Enter Move to folder") For Each f In fso.GetFolder(fileLocation).Files If LCase(fso.GetExtensionName(f)) = "csv" Then .Workbooks.Open .Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited,,,,,,,True,"|" .ActiveWorkbook.SaveAs .ActiveWorkbook.Path & "\1.xls", xlNormal .Quit End If Next 

相当混淆至less说:S再一次的帮助是非常感谢!

“CStr(objFolder.self.path)”计算为一个string,所以不应该在分配中使用Set (仅用于对象)。

尝试这个:

 Const xlDelimited = 1 Const xlNormal = -4143 Set Excel = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") Dim Excel dim objShell dim objFolder Dim fileLocation set objShell = CreateObject("shell.application") set objFolder = objshell.BrowseForFolder(0, "Select File Location", 1, "H:\") set fileLocation = fso.GetFolder(objFolder.self.path) Set Excel = CreateObject("Excel.Application") Set fso = CreateObject("Scripting.FileSystemObject") folderDestination = InputBox("Enter Move to folder") For Each f In fso.GetFolder(fileLocation).Files If LCase(fso.GetExtensionName(f)) = "csv" Then .Workbooks.Open .Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited,,,,,,,True,"|" .ActiveWorkbook.SaveAs .ActiveWorkbook.Path & "\1.xls", xlNormal .Quit End If Next