0

谁能解释为什么这不起作用,它抛出一个错误说:

行:14 字符:1 错误:需要对象:'[字符串:“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

至少可以说很困惑:S 再次非常感谢任何帮助!

4

2 回答 2

2

"CStr(objFolder.self.path)" 计算为字符串,因此您不应在分配中使用Set(仅用于对象)。

于 2013-08-12T12:17:16.560 回答
0

尝试这个:

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
于 2013-08-12T14:40:34.577 回答