访问为文本运行Excel到列(循环多次)

时间:2013-09-13 20:29:50

标签: excel vba ms-access excel-vba

我的代码出了问题 - 我需要多次导入数据,但我需要先将数据正确编辑成分隔的列。

基本上,当我进入它时,程序可以执行列文本一次。但之后,它无法转换,即使这些文本文件的格式都相同。

示例数据 - 如您所见,它们具有分隔符(=和,)

"7",="AR",="",="",="720325438",="491.45",="0.00",="0.00",="0.00",="0.00"
"7",="AR",="",="",="720344843",="40.00",="0.00",="0.00",="0.00",="0.00"

代码:

Dim xlApp As Excel.Application
Dim xlSheet As Excel.Worksheet


For intCurrentfileNumber = 1 To intNumOfFiles
strCurrentFolderName = varFileArray(intCurrentfileNumber, 0)
strCurrentFileName = varFileArray(intCurrentfileNumber, 1)

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

xlApp.Workbooks.Open strCurrentFolderName & "\" & strCurrentFileName
Set xlSheet = xlApp.Worksheets(1)

xlSheet.("A1", Range("A" & Rows.Count).End(xlUp)).TextToColumns _
Destination:=Range("A1"), _
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=True, _
Tab:=False, _
Semicolon:=False, _
Comma:=True, _
Space:=False, _
Other:=True, _
OtherChar:="=", _
TrailingMinusNumbers:=True

ActiveWorkbook.Close (True)
xlApp.Quit
Set xlApp = Nothing
Set xlSheet = Nothing

DoCmd.TransferText acImportDelim, "Import Specification", "Staging", strCurrentFolderName & "\" & strCurrentFileName, True

Next intCurrentFileNumber