Bonjour le forum, j'ai dut recuperer un code pour l'adapter a ma situation, j'ai une feuille excel avec différentes informations et il faudrait que je puisse envoyer ces infos dans un PGI, simplement j'ai adapter le code a ma situation, je suis deja bien content, je n'ai aucun message d'erreur, il m'affiche même a la fin que l'importation a bien été réaliser, mais malheureusement lorsque je vais vérifier que l'importation a bien été faite dans mon PGI, ben il n'y a rien de nouveau :s.
Voici le code, je sait il est long, et bien compliquer pour moi, pour sa que je vous demande une fois de plus votre aide.
Code vba : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Dim V As Object, DP As Object
Dim CodeSoc As String
Dim OkConnect As Boolean, j As Long, bouton As OLEObject
Public Sub codeJnal()
    Call ImporterJnal
End Sub
Sub cpteaux()
    Call ImporterAuxiliaire
End Sub
Sub cpteAna()
    Call ImporterSection
End Sub
Sub cpteGen()
    Call ImporterGénéraux
End Sub
Sub ecr()
    Call ImporterPGI
End Sub
Sub CommandButton1_Click()
Dim classeur As String, nomfeuille As String, nomfeuil As String, nomfichier As String, nouvellefeuille As String
    classeur = ActiveWorkbook.Name
    nomfeuil = ActiveSheet.Name
    nouvellefeuille = Sheets(2).Name
    Sheets(nouvellefeuille).Activate
    Sheets(nouvellefeuille).Select
    With Sheets(nouvellefeuille)
        j = 1
        dl = .Range("a" & Rows.Count).End(xlUp).Row
        For i = 1 To dl
            If Sheets(nouvellefeuille).Cells(i, 3).Value = "OD" Then
                Sheets(nouvellefeuille).Cells(j, 105).Value = Sheets(nouvellefeuille).Cells(i, 2).Value
                Sheets(nouvellefeuille).Cells(j, 106).Value = Sheets(nouvellefeuille).Cells(i, 4).Value
                Sheets(nouvellefeuille).Cells(j, 107).Value = Sheets(nouvellefeuille).Cells(i, 6).Value
                Sheets(nouvellefeuille).Cells(j, 108).Value = Sheets(nouvellefeuille).Cells(i, 7).Value
                Sheets(nouvellefeuille).Cells(j, 109).Value = Sheets(nouvellefeuille).Cells(i, 8).Value
                Sheets(nouvellefeuille).Cells(j, 110).Value = Sheets(nouvellefeuille).Cells(i, 15).Value
                Sheets(nouvellefeuille).Cells(j, 113).Value = Sheets(nouvellefeuille).Cells(i, 75).Value
                Sheets(nouvellefeuille).Cells(j, 114).Value = Sheets(nouvellefeuille).Cells(i, 48).Value
                If Sheets(nouvellefeuille).Cells(i, 11).Value = "D" Then
                    Sheets(nouvellefeuille).Cells(j, 111).Value = Sheets(nouvellefeuille).Cells(i, 12).Value
                    If Sheets(nouvellefeuille).Cells(i, 12).Value < 0 Then
                        Sheets(nouvellefeuille).Cells(j, 111).Value = -Sheets(nouvellefeuille).Cells(j, 111).Value
                    End If
                ElseIf Sheets(nouvellefeuille).Cells(i, 11).Value = "C" Then
                    Sheets(nouvellefeuille).Cells(j, 112).Value = Sheets(nouvellefeuille).Cells(i, 12).Value
                    If Sheets(nouvellefeuille).Cells(i, 12).Value < 0 Then
                        Sheets(nouvellefeuille).Cells(j, 112).Value = -Sheets(nouvellefeuille).Cells(j, 112).Value
                    End If
                End If
                j = j + 1
            End If
        Next
    End With
 
        Sheets(nouvellefeuille).Columns("DA:DA").Select
        ActiveWorkbook.Names.Add Name:="E_DATECOMPTABLE", RefersToR1C1:="=Ecriture!C105"
        Sheets(nouvellefeuille).Columns("DB:DB").Select
        ActiveWorkbook.Names.Add Name:="E_GENERAL", RefersToR1C1:="=Ecriture!C106"
        Sheets(nouvellefeuille).Columns("DC:DC").Select
        ActiveWorkbook.Names.Add Name:="E_AUXILAIRE", RefersToR1C1:="=Ecriture!C107"
        Sheets(nouvellefeuille).Columns("DD:DD").Select
        ActiveWorkbook.Names.Add Name:="E_REFINTERNE", RefersToR1C1:="=Ecriture!C108"
        Sheets(nouvellefeuille).Columns("DE:DE").Select
        ActiveWorkbook.Names.Add Name:="E_LIBELLE", RefersToR1C1:="=Ecriture!C109"
        Sheets(nouvellefeuille).Columns("DF:DF").Select
        ActiveWorkbook.Names.Add Name:="E_DEVISE", RefersToR1C1:="=Ecriture!C110"
        Sheets(nouvellefeuille).Columns("DG:DG").Select
        ActiveWorkbook.Names.Add Name:="E_DEBIT", RefersToR1C1:="=Ecriture!C111"
        Sheets(nouvellefeuille).Columns("DH:DH").Select
        ActiveWorkbook.Names.Add Name:="E_CREDIT", RefersToR1C1:="=Ecriture!C112"
        Sheets(nouvellefeuille).Columns("DI:DI").Select
        ActiveWorkbook.Names.Add Name:="E_TABLE0", RefersToR1C1:="=Ecriture!C113"
        Sheets(nouvellefeuille).Columns("DJ:DJ").Select
        ActiveWorkbook.Names.Add Name:="E_LIBRETEXTE0", RefersToR1C1:="=Ecriture!C114"
        EcritureMaxi
 
 
 
 
 
 
 
    'bouton.delete
End Sub
 
'Bouton Ecriture
Sub EcritureMaxi()
Dim irow As Integer, icol As Integer, prow As Integer, drow As Integer
Dim cel As Range
Dim adate As String
Dim xdevise As String, xdate As String
Dim smessage As String
Dim idebit As Currency, icredit As Currency
 
   idebit = 0
   icredit = 0
   smessage = ""
 
   xdevise = ""
   irow = 1
   icol = 105
'Colonne cpte général débit ou crédit
 
   anom = "Libre"
 
Traitement:
   ActiveWorkbook.Names.Add Name:="_OD_" & anom, RefersToR1C1:="=" + afeuille + "!R" + CStr(j) + _
                                                               "C" + CStr(icol) + _
                                                               ":R" + CStr(irow) + _
                                                               "C" + CStr(icol + 10)
'selection la zone de résultat
Application.Goto reference:="_OD_" & anom
With Selection.Font
    .Name = "Arial"
    .FontStyle = "Normal"
    .Size = 10
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
End With
 
Selection.Copy
 
 
sRet = sGenereEcritures
 
 
If (Len(sRet) = 0) And OkConnect Then
    MsgBox " L'ECRITURE A ETE COMPTABILISEE !"
    Application.Goto reference:="_OD_" & anom
    Selection.delete Shift:=xlUp
    Application.CutCopyMode = False
Else
    MsgBox "PROBLEME : L'ECRITURE N'A PAS ETE COMPTABILISEE !"
    Application.Goto reference:="_OD_" & anom
    Selection.delete Shift:=xlUp
    Application.CutCopyMode = False
End If
 
fin:
    'ActiveSheet.Protect
    If Len(smessage) > 0 Then
      MsgBox (smessage)
    End If
    Application.Goto reference:=ActiveSheet.Range("A1"), Scroll:=True
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
Function sGenereEcritures() As String
Dim ret, dep, fol, acpte, Nat As String
Dim i, j As Integer
 
ret = ""
'ret = "Erreur : écriture non passée !"
On Error GoTo fin
 
ReConnecte
If Not OkConnect Then
      MsgBox "Impossible de connaitre le dossier en cours dans la compta."
        GoTo fin
End If
 
 
If fol = "" Then fol = 0
dep = Cells(2, 3).Value 'DOIT PRENDRE LA VALEUR DU JOURNAL SELECTIONNER
 
'28/07 contrôle de la nature du journal avant génération, définir nat avant
Nat = V.GetNatureJrl(dep) 'DOIT PRENDRE LA NATURE DU JOURNAL
'If ((Nat <> "ANO") Or (Nat = "VEN")) And (Nat <> "") Then
 If ((Nat = "OD") Or (Nat = "REG")) Then
    ret = ""
 
    Else
 
   ret = "Nature du journal incorrect... Elle doit être de nature OD"
   GoTo fin
 End If
 
 
If Not V Is Nothing Then
 ret = V.TraiteEcrituresComptesRevision(dep, fol, "TRUE")
 End If
fin:
If ret <> "" Then
    If ret = "EPZ_ERRJALLIB" Then
        MsgBox "Le journal n'est pas de type libre. Les écritures sont générées à la date de la première ligne."
        ret = ""
    Else
        MsgBox ret
    End If
 sGenereEcritures = ret
End If
End Function
'Se déconnecter, puis se reconnecter à la compta
Sub ReConnecte()
If OkConnect Then
    Set V = Nothing
    CodeSoc = ""
    Set DP = Nothing
End If
OkConnect = False
Connecte (1)
End Sub
'Se connecter à la compta
Function Connecte(icc As Integer)
Dim hWnd As Long
Dim hWndCegidPgi As Long
 
If Not OkConnect Then
    CodeSoc = ""
    ' MISE EN COMMENTAIRE POUR VERSION 2006 ajout me
    'hWndCegidPgi = FindWindow(vbNullString, "CegidPgi")
    'If hWndCegidPgi <> 0 Then
    '    hWnd = FindWindow(vbNullString, "Comptabilité PGI Expert")
    'Else
    '    hWnd = FindWindow(vbNullString, "Comptabilité PGI Expert")
    'End If
    'If hWnd = 0 Then
    '     hWnd = FindWindow(vbNullString, "Comptabilité S5")
    'End If
    'If hWnd = 0 And icc = 1 Then
    '  OkConnect = False
    '  Connecte = False
    '  Exit Function
    'End If
    ' fin ajout me
 
     ' ajout me pour version 2006
    hWnd = FindWindow(vbNullString, "Comptabilité")
    If hWnd = 0 And icc = 1 Then
      OkConnect = False
      Connecte = False
      Exit Function
    End If
    ' fin ajout me
 
    On Error GoTo PasConnecte
      Set V = CreateObject("Halley.HalleyWindow")
      CodeSoc = V.GetCodeSociete
      If InStr(CodeSoc, "#Erreur") <> 0 Then
        OkConnect = False
        Connecte = False
      End If
End If
OkConnect = True
Connecte = True
Exit Function
PasConnecte:
   OkConnect = False
   Connecte = False
End Function
D'avance merci bcp.