Bonjour,
je travaille sous Sage 100 gest co et compta version 10 base propriétaire.
Ci dessous le code qui me permet d'importer une balance générale sous excel avec les totaux debit crédit et les soldes.
Cela répondra peut être à votre question.
il faut d'abord:
-créer un dsn à partir du pilote sage gestion commerciale (ici "BASEGESTCO")
-référencer l'activeX microsoft ADO version ..., dans le fichier excel,
-Déclarer les fonctions TotalMvtSolde, ....
comme suit
- Code: Tout sélectionner
Option Explicit
Declare Function TotalMvtSolde Lib "CBODBC32" (ByVal CG_Num As String, ByVal CT_Num As String, ByVal JO_Num As String, ByVal Debut As String, ByVal Fin As String, cumul As Double) As Integer
Declare Function TotalMvtDebit Lib "CBODBC32" (ByVal CG_Num As String, ByVal CT_Num As String, ByVal JO_Num As String, ByVal Debut As String, ByVal Fin As String, cumul As Double) As Integer
Declare Function TotalMvtCredit Lib "CBODBC32" (ByVal CG_Num As String, ByVal CT_Num As String, ByVal JO_Num As String, ByVal Debut As String, ByVal Fin As String, cumul As Double) As Integer
et ensuite travailler sur une liaison ADODB pour extraire les données recherchées,
- Code: Tout sélectionner
Sub ImporterBalance(Debut As String, Fin As String)
Dim BASE As New ADODB.Connection
Dim RST_CG As New ADODB.Recordset
Dim RSQL As String
Dim i As Long
Dim Code As Integer
Dim TotalDebit As Double, TotalCredit As Double, solde As Double
BASE.Open "Dsn=BASEGESTCO;Uid=xxx"
RSQL = "SELECT * FROM F_COMPTEG"
RST_CG.Open RSQL, BASE, adOpenForwardOnly, adLockOptimistic
If RST_CG.BOF And RST_CG.EOF Then GoTo Fin
i = 0
Do Until RST_CG.EOF
Code = TotalMvtDebit(RST_CG("CG_NUM"), "", "", Debut, Fin, TotalDebit)
Code = TotalMvtCredit(RST_CG("CG_NUM"), "", "", Debut, Fin, TotalCredit)
If Not (TotalDebit = 0 And TotalCredit = 0) Then
ActiveCell.Offset(1, 0).Select
ActiveCell.Offset(0, 0) = RST_CG("CG_NUM")
ActiveCell.Offset(0, 1) = RST_CG("CG_INTITULE")
ActiveCell.Offset(0, 2) = TotalDebit
ActiveCell.Offset(0, 3) = TotalCredit
Code = TotalMvtSolde(RST_CG("CG_NUM"), "", "", Debut, Fin, solde)
If solde > 0 Then
ActiveCell.Offset(0, 4) = solde
Else
ActiveCell.Offset(0, 5) = -solde
End If
i = i + 1
End If
RST_CG.MoveNext
Loop
Fin:
RST_CG.Close
BASE.Close
End Sub
A+