Jump to content
Fórum Script Brasil
  • 0

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


Vitor93

Question

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
        gConexao.Close
        Set gConexao = Nothing
    End If
End Sub


Sub ConectaBanco()

 

'Dim dbs As DataBase, rst As Recordset

   
Módulo13.lsConectar

 


 

'CIF = "CIF"
ORI = "BRISAMAR"

 

Set rs = New ADODB.Recordset
 

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

 
Planilha1.Select

 


Planilha1.Range("A2").CopyFromRecordset rs

 


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

 

    

 

Módulo13.lsDesconectar

 

 

End Sub

 

image.thumb.png.763933d7fdf36f9ab8ae79e6a51af393.png

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.

Guest
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
      152.1k
    • Total Posts
      651.9k
×
×
  • Create New...