|
|
|
|
|
Dicas
|
|
Visual Basic (Banco de Dados)
|
|
|
Título da Dica: Leia Arquivos do Excel e Textos usando ADO
|
|
|
|
Postada em 29/1/2003 por Felipe
'Lendo do excel usando ADO Public Function Read_Excel _ (ByVal sFile _ As String) As ADODB.Recordset
On Error GoTo fix_err Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim sconn As String
rs.CursorLocation = adUseClient rs.CursorType = adOpenKeyset rs.LockType = adLockBatchOptimistic
sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile rs.Open "SELECT * FROM [sheet1$]", sconn Set Read_Excel = rs Set rs = Nothing Exit Function fix_err: Debug.Print Err.Description + " " + _ Err.Source, vbCritical, "Import" Err.Clear End Function
'Lendo arquivo de texto
Public Function Read_Text_File() As ADODB.Recordset
Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim conn As ADODB.Connection Set conn = New ADODB.Connection conn.Open "DRIVER={Microsoft Text Driver (*.txt; *.csv)};" & _ "DBQ=" & App.Path & ";", "", ""
rs.Open "select * from [test#txt]", conn, adOpenStatic, _ adLockReadOnly, adCmdText Set Read_Text_File = rs Set rs = Nothing Set conn = Nothing End Function
|
|
|
|
|