Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting from one Excel file to another, how do you display info Greg Excel Discussion (Misc queries) 2 March 23rd 09 06:27 PM
Connecting a Pivot Table to .Tab Data file ** Minimise the connexion setup hassle No Name Excel Discussion (Misc queries) 3 March 12th 09 01:59 PM
connecting wordpad and excel Jan Excel Discussion (Misc queries) 1 May 4th 07 01:37 PM
Connecting to SQL from Excel Keith La Force Excel Programming 4 March 2nd 05 09:27 PM
Connecting to excel datasheets using C# Narwe Excel Programming 1 November 22nd 04 02:01 PM


All times are GMT +1. The time now is 06:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"