我不是程序员,所以下面的代码不是由我创建的。我试图复制一个新帐户的功能之一,我在这一行遇到了错误:
rs.Open "Select * From " & file2 & ".txt order by [Security]", _
conn, adOpenStatic, adLockUnspecified, adCmdText
它引用的文件类似于其他文件,所以我不确定问题是什么。我检查了所有的拼写,我只是想不出来。一些帮助或甚至是如何排除故障将非常感激。
Public Sub RunRecon()
Application.Calculation = xlManual
ReconLDSF
ReconUCAL
ReconCNSL
ReconMONT
ReconMAC50
ReconMAC40
ReconTOU
ReconVER
Application.Calculation = xlAutomatic
End Sub
Function ReconTOU()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim adcomm As New ADODB.Command
Dim path As String
Dim loDataWrk As Worksheet
Set loDataWrk = Worksheets("TOU")
loDataWrk.Range("A3:AZ5000").ClearContents
path = "L:\ForumAxys\ForumImports\Mellon\Versus\"
conn.Open "Provider=Microsoft.ACE" _
& ".OLEDB.12.0;Data Source=" & path _
& ";Extended Properties='text;HDR=Yes;" _
& "FMT=Delimited'"
rs.Open "Select * from [Custody Holdings.csv] where [Account Number] = '492617' and [Traded Shares/Par] <> '0' order by [Security Description 1]", _
conn, adOpenStatic, adLockReadOnly, adCmdText
cnt = 3
Name = "NA"
Do While Not rs.EOF
If Left(rs.Fields("Security Description 1"), 8) = "THE LINK" Then
Name = Replace(rs.Fields("Security Description"), "THE ", "")
Else
Name = rs.Fields("Security Description 1")
End If
loDataWrk.Cells(cnt, 1) = Name
loDataWrk.Cells(cnt, 2) = CLng(rs.Fields("Settled Shares/Par"))
cnt = cnt + 1
rs.MoveNext
Loop
Range("A3:B" & cnt - 1).Sort Key1:=Range("A3"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
conn.Close
path = "L:\Axys38\txt\"
file2 = "tou"
conn.Open "Provider=Microsoft.ACE" _
& ".OLEDB.12.0;Data Source=" & path _
& ";Extended Properties='text;HDR=Yes;" _
& "FMT=TabDelimited'"
**rs.Open "Select * From " & file2 & ".txt order by [Security]", _
conn, adOpenStatic, adLockUnspecified, adCmdText**
cnt = 3
Do While Not rs.EOF
loDataWrk.Cells(cnt, 3) = rs.Fields("Security")
loDataWrk.Cells(cnt, 4) = rs.Fields("Quantity")
loDataWrk.Cells(cnt, 5) = "=B" & cnt & "-D" & cnt
cnt = cnt + 1
rs.MoveNext
Loop
conn.Close
End Function
以下是两个.txt文件。第二个工作(没有改变任何编码引用它),第一个没有。它们被同一个脚本分割出来。它们似乎具有相同的格式和相同的标题......我不明白我可能会改变什么。
Security Symbol Security Quantity Local ISO Price Spot Rate Total Cost Unrealized Gain/Loss Market Value
AAAA AAAAA 10000 SGD 1.23 1.2762 13089.5278 -748.20 12341.3258
BBBB BBBBB 494 USD 23.45 1.0000 13011.6900 -1427.39 11584.3000
Security Symbol Security Quantity Local ISO Price Spot Rate Total Cost Unrealized Gain/Loss Market Value
AAA AAAAA 18200 JPY 21.90 97.9000 486611.8961 -88033.76 398578.1410
答案 0 :(得分:1)
我认为您需要添加schema.ini
文件来解决您的问题。因此,根据this information,您需要执行以下操作:
1.创建文本文件schema.ini
并将其保存在tou.txt
文件所在的文件夹中。
2.你的schemat.ini
应该是这样的:
[Tou.Txt]
ColNameHeader = True
CharacterSet = ANSI
Format=TabDelimited
现在,您的代码应该适用于Tou.Txt
,但如果它们都在同一个文件夹中,则无法用于其他文件。如果是这样,您需要为导入的所有其他文本文件添加schema.ini
个相似部分。