|
您好,请教个问题。vba+ado+sql提取csv txt 中字母数字组合的内容,结果只留下数字。例如F3F2,取出来是2。KF003654,提取出来是3654. 大写的FKS三个字母其一+数字组合的数据都提取不出来,会屏蔽字母,其他行数据还会出现空值。原因何在? 代码如下:先后尝试了execute(),format,各种修改。测试均提取不到想要的内容。 Sub chaxuntxt() Dim u As Integer, cnnstr, mypath, sql As String Dim cnn, rs As Object mypath = ThisWorkbook.Path & "\" Set cnn = CreateObject("adodb.Connection") Set rs = CreateObject("adodb.recordset") cnnstr = "provider=microsoft.ace.oledb.12.0;data source =" & mypath & ";extended properties='text;hdr=yes;imex=1;fmt=delimited(,)'" cnn.Open cnnstr sql = "select * from [测试.CSV] " 'Set rs = cnn.Execute(sql) rs.Open sql, cnn Range("a12").CopyFromRecordset rs For u = 0 To rs.Fields.Count - 1 Cells(11, u + 1).Value = rs.Fields(u).Name Next u cnn.Close Set cnn = Nothing End Sub |
|