Jump to content
Fórum Script Brasil
  • 0

Código de conexão do Access com o Excel



Bom dia!


Pessoal, estou tentando fazer um script para que ele copie umas informações no banco do ACCESS e depois cole no excel, vocês poderiam me auxiliar?


Já comecei a fazer o código porém está dando erro



Option Explicit
Function ConectarBanco_FILIAIS(conexao As ADODB.Connection)


Dim Provider As String, dataSource As String, caminho As String
Dim connectionString As String


caminho = ThisWorkbook.Path & "\3.0.Accdb;"


Provider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dataSource = "Data Source=" & caminho


connectionString = Provider & dataSource


conexao.Open connectionString


End Function

Private Sub lsDesconectar()
    If Not gConexao Is Nothing Then
        Set gConexao = Nothing
    End If
End Sub

Sub ConectaBanco()


'Dim dbs As DataBase, rst As Recordset




'CIF = "CIF"


Set rs = New ADODB.Recordset

rs.Open "Select * FROM TB_MRS WHERE Origem'" & ORI & "' ", gConexao, 3, 3



Planilha1.Range("A2").CopyFromRecordset rs


    If Not rs Is Nothing Then
        Set rs = Nothing
    End If







End Sub



Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Create New...