[VBA-E] Lier une macro a une feuille excel
bonjour.:mrgreen:
Je n'y connais rien a VB et je cherche a extraire des infos d'une base de donnee PostgreSQL pour les récupérer dans une feuille excel.
Pour l'instant, j'ai installé le datasource Postgres odbc et voici un script que j'ai réadapté pour la connection:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| Sub connection()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
'Open the connection
cn.Open "DSN=PostgreSQL;" & _
"UID=MonUSerNAme;" & _
"PWD=MonPassword;" & _
"Database=MaDB"
'For updateable recordsets we would typically open a Dynamic recordset.
'Forward Only recordsets are much faster but can only scroll forward and
'are read only. Snapshot recordsets are read only, but scroll in both
'directions.
rs.Open "SELECT * FROM recover", cn, adOpenDynamic
'Loop though the recordset and print the results
'We will also update the accessed column, but this time access it through
'the Fields collection. ISO-8601 formatted dates/times are the safest IMHO.
While Not rs.EOF
Debug.Print rs!Sr_id & ": " & rs!Sr_open
rs.MoveNext
Wend
'Refresh the recordset to get that last record...
'rs.Refresh
'Get the record count
'rs.MoveLast
'rs.MoveFirst
'MsgBox rs.RecordCount & " Records are in the recordset!"
'Cleanup
If rs.State <> adStateClosed Then rs.Close
Set rs = Nothing
If cn.State <> adStateClosed Then cn.Close
Set cn = Nothing
End Sub |
Quand j'ai compilé au debut ca passait pas, fallait activer les controle activeX.
Maintenant ca compile, mais il se passe rien... comment on fait pour dire qu'on veut que l'output se fasse dans une sheet? :roll: