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 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
| Public NomFichier As String
Public CheminFichier As String
Public CeClasseur As String
Public Enregistrer As String
Public Imprimer As String
Public FacDev As String
Public Préparateur As String
Public NomduClasseur As String
Public NbItemsList1 As Integer
Public NbItemsList2 As Integer
Public NbItemsList3 As Integer
Public NomClasseurPrincipal As String
Sub Bilan_Factures_Non_Payées()
NomClasseurPrincipal = ActiveWorkbook.Name
UserForm6.Show
End Sub
Private Sub CommandButton1_Click()
Dim i As Integer
Dim Fichier_à_ouvrir As String
Dim Chemin As String
Dim Bouton_Enr1 As OLEObject
Dim Bouton_Imp1 As OLEObject
'-------------------------------------------------------------------------
For i = 1 To ListView1.ListItems.Count
If ListView1.ListItems(i).Selected = True Then
Fichier_à_ouvrir = ListView1.ListItems(i).Text
Chemin = "E:\Dir1\Dir2\Dir3\Dir4\Dir5\" & Fichier_à_ouvrir & ".xls"
Workbooks.Open Filename:=Chemin
Set NomClasseur1 = ActiveWorkbook
Range("C5").Select
On Error Resume Next
Set Bouton_Enr1 = ActiveSheet.OLEObjects("Enregistrer")
On Error GoTo 0
If Bouton_Enr1 Is Nothing Then
Set Bouton_Enr1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Enr1
.Name = "Enregistrer"
.Left = 10
.Top = 30
.Width = 60
.Height = 25
.Object.Caption = "Enregistrer"
End With
End If
AjoutCodeEnregistrer1
On Error Resume Next
Set Bouton_Imp1 = ActiveSheet.OLEObjects("Imprimer")
On Error GoTo 0
If Bouton_Imp1 Is Nothing Then
Set Bouton_Imp1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Imp1
.Name = "Imprimer"
.Left = 10
.Top = 60
.Width = 60
.Height = 25
.Object.Caption = "Imprimer"
End With
End If
AjoutCodeImprimer1
End If
Next
'-------------------------------------------------------------------------
For j = 1 To ListView2.ListItems.Count
If ListView2.ListItems(j).Selected = True Then
Fichier_à_ouvrir = ListView2.ListItems(j).Text
Chemin = "E:\Dir1\Dir2\Dir3\Dir4\Dir5\" & Fichier_à_ouvrir & ".xls"
Workbooks.Open Filename:=Chemin
Set NomClasseur1 = ActiveWorkbook
Range("C5").Select
On Error Resume Next
Set Bouton_Enr1 = ActiveSheet.OLEObjects("Enregistrer")
On Error GoTo 0
If Bouton_Enr1 Is Nothing Then
Set Bouton_Enr1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Enr1
.Name = "Enregistrer"
.Left = 10
.Top = 30
.Width = 60
.Height = 25
.Object.Caption = "Enregistrer"
End With
End If
AjoutCodeEnregistrer1
On Error Resume Next
Set Bouton_Imp1 = ActiveSheet.OLEObjects("Imprimer")
On Error GoTo 0
If Bouton_Imp1 Is Nothing Then
Set Bouton_Imp1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Imp1
.Name = "Imprimer"
.Left = 10
.Top = 60
.Width = 60
.Height = 25
.Object.Caption = "Imprimer"
End With
End If
AjoutCodeImprimer1
End If
Next
'---------------------------------------------------------------------------
For k = 1 To ListView3.ListItems.Count
If ListView3.ListItems(k).Selected = True Then
Fichier_à_ouvrir = ListView3.ListItems(k).Text
Chemin = "E:\Dir1\Dir2\Dir3\Dir4\Dir5\" & Fichier_à_ouvrir & ".xls"
Workbooks.Open Filename:=Chemin
Set NomClasseur1 = ActiveWorkbook
Range("C5").Select
On Error Resume Next
Set Bouton_Enr1 = ActiveSheet.OLEObjects("Enregistrer")
On Error GoTo 0
If Bouton_Enr1 Is Nothing Then
Set Bouton_Enr1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Enr1
.Name = "Enregistrer"
.Left = 10
.Top = 30
.Width = 60
.Height = 25
.Object.Caption = "Enregistrer"
End With
End If
AjoutCodeEnregistrer1
On Error Resume Next
Set Bouton_Imp1 = ActiveSheet.OLEObjects("Imprimer")
On Error GoTo 0
If Bouton_Imp1 Is Nothing Then
Set Bouton_Imp1 = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Bouton_Imp1
.Name = "Imprimer"
.Left = 10
.Top = 60
.Width = 60
.Height = 25
.Object.Caption = "Imprimer"
End With
End If
AjoutCodeImprimer1
End If
Next
'---------------------------------------------------------------------------
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label2_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Label4_Click()
End Sub
Private Sub Label5_Click()
End Sub
Private Sub Label6_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub Label8_Click()
End Sub
Private Sub Label9_Click()
End Sub
Private Sub ListView1_BeforeLabelEdit(Cancel As Integer)
End Sub
Private Sub ListView2_BeforeLabelEdit(Cancel As Integer)
End Sub
Private Sub ListView3_BeforeLabelEdit(Cancel As Integer)
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Change()
End Sub
Private Sub TextBox3_Change()
End Sub
Private Sub UserForm_Initialize()
'----- remplissage ListView------------------------
ListView1.Gridlines = True
Me.ListView1.CheckBoxes = True
ListView1.MultiSelect = True
With ListView1
'Définit le nombre de colonnes et Entêtes
With .ColumnHeaders
'Supprime les anciens entêtes
.Clear
'Ajoute 4 colonnes en spécifiant le nom de l'entête
'la largeur des colonnes et centre
.Add , , "Nom Facture", 130
.Add , , "Montant", 40, lvwColumnCenter
.Add , , "Relance Mail", 60, lvwColumnCenter
.Add , , "Relance Courrier", 70, lvwColumnCenter
End With
'Remplissage des colonnes
Sheets("Factures J").Select
Range("A4").Select
n = 1
m = 1
p = 1
Do While Not (IsEmpty(ActiveCell))
i = ActiveCell
With .ListItems
.Add , , i
End With
Selection.Offset(0, 1).Select
j = ActiveCell
.ListItems(n).ListSubItems.Add , , j
Selection.Offset(0, 1).Select
k = ActiveCell
.ListItems(m).ListSubItems.Add , , k
Selection.Offset(0, 1).Select
l = ActiveCell
.ListItems(p).ListSubItems.Add , , l
Selection.Offset(1, -3).Select
n = n + 1
m = m + 1
p = p + 1
Loop
End With
ListView1.ListItems(1).Selected = False
Set ListView1.SelectedItem = Nothing
'---------------------------------------------------------------
ListView2.Gridlines = True
Me.ListView2.CheckBoxes = True
ListView2.MultiSelect = True
With ListView2
'Définit le nombre de colonnes et Entêtes
With .ColumnHeaders
'Supprime les anciens entêtes
.Clear
'Ajoute 4 colonnes en spécifiant le nom de l'entête
'la largeur des colonnes et centre
.Add , , "Nom Facture", 130
.Add , , "Montant", 40, lvwColumnCenter
.Add , , "Relance Mail", 60, lvwColumnCenter
.Add , , "Relance Courrier", 70, lvwColumnCenter
End With
'Remplissage des colonnes
Sheets("Factures J-F").Select
Range("A4").Select
n = 1
m = 1
p = 1
Do While Not (IsEmpty(ActiveCell))
i = ActiveCell
With .ListItems
.Add , , i
End With
Selection.Offset(0, 1).Select
j = ActiveCell
.ListItems(n).ListSubItems.Add , , j
Selection.Offset(0, 1).Select
k = ActiveCell
.ListItems(m).ListSubItems.Add , , k
Selection.Offset(0, 1).Select
l = ActiveCell
.ListItems(p).ListSubItems.Add , , l
Selection.Offset(1, -3).Select
n = n + 1
m = m + 1
p = p + 1
Loop
End With
ListView2.ListItems(1).Selected = False
Set ListView2.SelectedItem = Nothing
'---------------------------------------------------------
ListView3.Gridlines = True
Me.ListView3.CheckBoxes = True
ListView3.MultiSelect = True
With ListView3
'Définit le nombre de colonnes et Entêtes
With .ColumnHeaders
'Supprime les anciens entêtes
.Clear
'Ajoute 4 colonnes en spécifiant le nom de l'entête
'la largeur des colonnes et centre
.Add , , "Nom Facture", 130
.Add , , "Montant", 40, lvwColumnCenter
.Add , , "Relance Mail", 60, lvwColumnCenter
.Add , , "Relance Courrier", 70, lvwColumnCenter
End With
'Remplissage des colonnes
Sheets("Factures S").Select
Range("A4").Select
n = 1
m = 1
p = 1
Do While Not (IsEmpty(ActiveCell))
i = ActiveCell
With .ListItems
.Add , , i
End With
Selection.Offset(0, 1).Select
j = ActiveCell
.ListItems(n).ListSubItems.Add , , j
Selection.Offset(0, 1).Select
k = ActiveCell
.ListItems(m).ListSubItems.Add , , k
Selection.Offset(0, 1).Select
l = ActiveCell
.ListItems(p).ListSubItems.Add , , l
Selection.Offset(1, -3).Select
n = n + 1
m = m + 1
p = p + 1
Loop
End With
ListView3.ListItems(1).Selected = False
Set ListView3.SelectedItem = Nothing
'--------------------------------------------------
'Spécifie l'affichage en mode "Détails"
ListView1.View = lvwReport
ListView2.View = lvwReport
ListView3.View = lvwReport
Sheets("Factures J").Select
Columns("B:B").Find("----------", [B1], , , , xlPrevious).Select
ActiveCell.Offset(-1, 0).Select
MontantDuJ = ActiveCell.Value
TextBox1.Value = MontantDuJ
Sheets("Factures J-F").Select
Columns("B:B").Find("----------", [B1], , , , xlPrevious).Select
ActiveCell.Offset(-1, 0).Select
MontantDuJF = ActiveCell.Value
TextBox2.Value = MontantDuJF
Sheets("Factures S").Select
Columns("B:B").Find("----------", [B1], , , , xlPrevious).Select
ActiveCell.Offset(-1, 0).Select
MontantDuS = ActiveCell.Value
TextBox3.Value = MontantDuS
End Sub
Sub AjoutCodeEnregistrer1()
'Référence à ajouter Microsoft Visual Basic for Application Extsensibility 5.3
Dim CeClasseur As VBComponent
Dim i As Integer
Dim NumCom As Integer
Dim Nom As String
Dim FacDev As String
Dim CheminFichier As String
Dim NomFichier As String
Dim Préparateur As String
Set CeClasseur = ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName)
With CeClasseur.CodeModule
i = .CountOfLines
.InsertLines i + 1, "Public NomClasseurPrincipal As String"
.InsertLines i + 2, "Sub Enregistrer_Click()"
.InsertLines i + 3, "Dim CheminFichier As String"
.InsertLines i + 4, "Dim NomFichier As String"
.InsertLines i + 5, "Dim LongNomFichier As Integer"
.InsertLines i + 6, "Dim FacDev As String"
.InsertLines i + 7, "Dim Préparateur As String"
.InsertLines i + 8, "Dim NomduClasseur As String"
.InsertLines i + 9, "Dim i As Integer"
.InsertLines i + 10, "Dim NombreLignes1 As Integer"
.InsertLines i + 11, "Dim NombreLignes2 As Integer"
.InsertLines i + 12, "Dim NombreLignes3 As Integer"
.InsertLines i + 13, "'"
.InsertLines i + 14, "'"
.InsertLines i + 15, "Range(""C5"").Select"
.InsertLines i + 16, "ActiveCell.Select"
.InsertLines i + 17, "ActiveCell.Offset(-2,3).Select"
.InsertLines i + 18, "FacDev = ActiveCell.Value"
.InsertLines i + 19, "Range(""J14"").select"
.InsertLines i + 20, "Préparateur = ActiveCell.value"
.InsertLines i + 21, "'"
.InsertLines i + 22, "If FacDev=""Facture"" Then"
.InsertLines i + 23, "CheminFichier = ThisWorkbook.Path & ""\"""
.InsertLines i + 24, "NomFichier = ActiveWorkbook.Name"
.InsertLines i + 25, "LongNomFichier = Len(NomFichier)"
.InsertLines i + 26, "NomFichier = Mid(NomFichier,1,LongNomFichier-4)"
.InsertLines i + 27, "'"
.InsertLines i + 28, "With ActiveWorkbook"
.InsertLines i + 29, ".SaveAs FileName:=CheminFichier & NomFichier"
.InsertLines i + 30, "NomClasseurPrincipal.Activate"
.InsertLines i + 31, "'"
.InsertLines i + 32, "'"
.InsertLines i + 33, "If Préparateur = ""S"" Then"
.InsertLines i + 34, "Sheets(""Factures S"").Select"
.InsertLines i + 35, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 36, "NombreLignes3 = Selection.Rows.Count"
.InsertLines i + 37, "Range(""A4"").select"
.InsertLines i + 38, "'"
.InsertLines i + 39, "For i=1 To NombreLignes3"
.InsertLines i + 40, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 41, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 42, "Else:Selection.EntireRow.Delete"
.InsertLines i + 43, "End If"
.InsertLines i + 44, "Next"
.InsertLines i + 45, "'"
.InsertLines i + 46, "ElseIf Préparateur = ""J"" Then"
.InsertLines i + 47, "Sheets(""Factures J"").Select"
.InsertLines i + 48, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 49, "NombreLignes1 = Selection.Rows.Count"
.InsertLines i + 50, "Range(""A4"").select"
.InsertLines i + 51, "'"
.InsertLines i + 52, "For i=1 To NombreLignes1"
.InsertLines i + 53, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 54, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 55, "Else:Selection.EntireRow.Delete"
.InsertLines i + 56, "End If"
.InsertLines i + 57, "Next"
.InsertLines i + 58, "'"
.InsertLines i + 59, "Else: Préparateur = ""J-F"""
.InsertLines i + 60, "Sheets(""Factures J-F"").Select"
.InsertLines i + 61, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 62, "NombreLignes2 = Selection.Rows.Count"
.InsertLines i + 63, "Range(""A4"").select"
.InsertLines i + 64, "'"
.InsertLines i + 65, "'"
.InsertLines i + 66, "For i=1 To NombreLignes2"
.InsertLines i + 67, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 68, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 69, "Else:Selection.EntireRow.Delete"
.InsertLines i + 70, "End If"
.InsertLines i + 71, "Next"
.InsertLines i + 72, "'"
.InsertLines i + 73, "End If"
.InsertLines i + 74, "'"
.InsertLines i + 75, "Exit Sub"
.InsertLines i + 76, ".Close"
.InsertLines i + 77, "End With"
.InsertLines i + 78, "'"
.InsertLines i + 79, "Else: CheminFichier = ThisWorkbook.Path & ""\"""
.InsertLines i + 80, "NomFichier = ActiveWorkbook.Name"
.InsertLines i + 81, "LongNomFichier = Len(NomFichier)"
.InsertLines i + 82, "NomFichier = Mid(NomFichier,1,LongNomFichier-4)"
.InsertLines i + 83, "'"
.InsertLines i + 84, "With ActiveWorkbook"
.InsertLines i + 85, ".SaveAs FileName:=CheminFichier & NomFichier"
.InsertLines i + 86, "'"
.InsertLines i + 87, "'"
.InsertLines i + 88, "'"
.InsertLines i + 89, "If Préparateur = ""S"" Then"
.InsertLines i + 90, "Sheets(""Factures S"").Select"
.InsertLines i + 91, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 92, "NombreLignes3 = Selection.Rows.Count"
.InsertLines i + 93, "Range(""A4"").select"
.InsertLines i + 94, "'"
.InsertLines i + 95, "For i=1 To NombreLignes3"
.InsertLines i + 96, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 97, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 98, "Else:Selection.EntireRow.Delete"
.InsertLines i + 99, "End If"
.InsertLines i + 100, "Next"
.InsertLines i + 101, "'"
.InsertLines i + 102, "ElseIf Préparateur = ""J"" Then"
.InsertLines i + 103, "Sheets(""Factures J"").Select"
.InsertLines i + 104, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 105, "NombreLignes1 = Selection.Rows.Count"
.InsertLines i + 106, "Range(""A4"").select"
.InsertLines i + 107, "'"
.InsertLines i + 108, "For i=1 To NombreLignes1"
.InsertLines i + 109, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 110, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 111, "Else:Selection.EntireRow.Delete"
.InsertLines i + 112, "End If"
.InsertLines i + 113, "Next"
.InsertLines i + 114, "'"
.InsertLines i + 115, "Else: Préparateur = ""J-F"""
.InsertLines i + 116, "Sheets(""Factures J-F"").Select"
.InsertLines i + 117, "Range(""A4"",Range(""A4"").End(xlDown)).Select"
.InsertLines i + 118, "NombreLignes2 = Selection.Rows.Count"
.InsertLines i + 119, "Range(""A4"").select"
.InsertLines i + 120, "'"
.InsertLines i + 121, "'"
.InsertLines i + 122, "For i=1 To NombreLignes2"
.InsertLines i + 123, "If ActiveCell.Value <> NomFichier Then"
.InsertLines i + 124, "ActiveCell.Offset(1,0).Select"
.InsertLines i + 125, "Else:Selection.EntireRow.Delete"
.InsertLines i + 126, "End If"
.InsertLines i + 127, "Next"
.InsertLines i + 128, "'"
.InsertLines i + 129, "End If"
.InsertLines i + 130, "'"
.InsertLines i + 131, "Exit Sub"
.InsertLines i + 132, ".Close"
.InsertLines i + 133, "End With"
.InsertLines i + 134, "'"
.InsertLines i + 135, "End If"
.InsertLines i + 136, "End Sub"
End With
End Sub
Sub AjoutCodeImprimer1()
Dim CeClasseur As VBComponent
Dim j As Integer
Dim NumLigne As Integer
Dim NumColonne As Integer
Set CeClasseur = ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName)
With CeClasseur.CodeModule
j = .CountOfLines
.InsertLines j + 1, "Sub Imprimer_Click()"
.InsertLines j + 2, "'"
.InsertLines j + 3, "Dim NumLigne As Integer"
.InsertLines j + 4, "Dim NumColonne As Integer"
.InsertLines j + 5, "'"
.InsertLines j + 6, "Columns(""J:J"").Find(""----------"", [J1], , , , xlPrevious).Select"
.InsertLines j + 7, "ActiveCell.Offset(-1, 0).Select"
.InsertLines j + 8, "'"
.InsertLines j + 9, "NumLigne = ActiveCell.Row"
.InsertLines j + 10, "NumColonne = ActiveCell.Column"
.InsertLines j + 11, "'"
.InsertLines j + 12, "Range(""A1"" & "":J"" & NumLigne).Select"
.InsertLines j + 13, "'"
.InsertLines j + 14, "With Sheets(""Fac - Dev"").PageSetup"
.InsertLines j + 15, ".PrintArea = ""A1"" & "":J"" & NumLigne"
.InsertLines j + 16, ".PaperSize = xlPaperA4"
.InsertLines j + 17, ".CenterHorizontally = True"
.InsertLines j + 18, ".Orientation = xlPortrait"
.InsertLines j + 19, ".Zoom = False"
.InsertLines j + 20, ".FitToPagesWide = 1"
.InsertLines j + 21, ".FitToPagesTall = 2"
.InsertLines j + 22, "End With"
.InsertLines j + 23, "Sheets(""Fac - Dev"").PrintOut"
.InsertLines j + 24, "End Sub"
End With
End Sub |
Partager