1

我不是程序员,所以下面的代码不是由我创建的。我试图为一个新帐户复制其中一个功能,但我在这一行遇到了错误:

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
4

1 回答 1

1

我认为您需要添加schema.ini文件来解决您的问题。因此,根据此信息,您需要执行以下操作:

1.创建文本文件schema.ini并将其保存在文件所在的文件夹中tou.txt

2.你schemat.ini应该看起来像:

[Tou.Txt]
ColNameHeader = True
CharacterSet = ANSI
Format=TabDelimited

现在,如果它们都在同一个文件夹中,您的代码应该适用于其他文件,Tou.Txt但不能适用于其他文件。如果是这样,您需要为schema.ini您导入的所有其他文本文件添加到类似部分。

于 2013-06-25T21:47:21.303 回答