Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL-VBA, ADO not connecting to a TXT file
Could you give me a good link or sample about how to implement a EXCEL-VBA
with ADO. I mean, using EXCEL-VBA (forms, modules and classes) , to dynamically compare values in Excel and a TXT file. thanks Coco pd. I already tried and it did not work, I thought that was about "Project References" but I think I did it correctly. Now is showing VBA Project - References "Microsoft ADO Ext. 2.8 for DDL and Security" (last priority) and this is the copy of what I did: Sub TestGetTextFileData() GetTextFileData "SELECT * FROM mex1.txt", "c:\temp", Range("A3") End Sub Sub GetTextFileData(strSQL As String, strFolder As String, rngTargetCell As Range) Dim cn As ADODB.Connection, rs As ADODB.Recordset, f As Integer If rngTargetCell Is Nothing Then Exit Sub Set cn = New ADODB.Connection On Error Resume Next cn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _ "Dbq=" & strFolder & ";" & _ "Extensions=asc,csv,tab,txt;" On Error GoTo 0 If cn.State < adStateOpen Then Exit Sub Set rs = New ADODB.Recordset On Error Resume Next rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText On Error GoTo 0 If rs.State < adStateOpen Then cn.Close Set cn = Nothing Exit Sub End If For f = 0 To rs.Fields.Count - 1 rngTargetCell.Offset(0, f).Formula = rs.Fields(f).Name Next f rngTargetCell.Offset(1, 0).CopyFromRecordset rs rs.Close Set rs = Nothing cn.Close Set cn = Nothing End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
EXCEL-VBA, ADO not connecting to a TXT file
Hello you have to activate the "Microsoft ActiveX Data Object x.x Library and not the "Microsoft ADO Ext. 2.8 for DDL and Security" Regards miche -- michelxl ----------------------------------------------------------------------- michelxld's Profile: http://www.excelforum.com/member.php...fo&userid=1736 View this thread: http://www.excelforum.com/showthread.php?threadid=37992 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Connecting from one Excel file to another, how do you display info | Excel Discussion (Misc queries) | |||
Connecting a Pivot Table to .Tab Data file ** Minimise the connexion setup hassle | Excel Discussion (Misc queries) | |||
connecting wordpad and excel | Excel Discussion (Misc queries) | |||
Connecting to SQL from Excel | Excel Programming | |||
Connecting to excel datasheets using C# | Excel Programming |