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
|
Private Sub ExporteDansRapportParDate(ByVal rst As Recordset, ByVal dd As String)
On Error GoTo Err_ExporteDansRapportParDate
Dim appExcel As New Excel.Application 'Application Excel
Dim appExcelFeuille As Excel.Worksheet 'feuille de travail Excel
Set appExcel = Nothing
Set appExcelFeuille = Nothing
Dim X As Integer
'Ouverture du fichier Excel
appExcel.Visible = False
appExcel.Workbooks.Open "G:\CONTACT SECURITE\Rapports\RapportCS.xls", 3, False
'Sélection de la feuille de travail.
Set appExcelFeuille = appExcel.Workbooks(1).Worksheets(1)
'Inscription du titre
appExcelFeuille.Range("B" & 1) = "Rapport des Contacts"
appExcelFeuille.Range("B" & 2) = "À partir du " & dd
X = 5 'Point de départ
'Effacer le contenu existant.
While appExcelFeuille.Cells(X, 1) <> "" 'Tant qu'on arrivera pas a une ligne vide.
appExcelFeuille.Cells(X, 1) = ""
appExcelFeuille.Cells(X, 2) = ""
appExcelFeuille.Cells(X, 3) = ""
appExcelFeuille.Cells(X, 4) = ""
appExcelFeuille.Cells(X, 5) = ""
appExcelFeuille.Cells(X, 6) = ""
appExcelFeuille.Cells(X, 7) = ""
appExcelFeuille.Cells(X, 8) = ""
appExcelFeuille.Cells(X, 9) = ""
appExcelFeuille.Cells(X, 10) = ""
X = X + 1
Wend
X = 5 'Remettre le point de départ.
'Insertions des données dans la feulle de travail.
While Not rst.EOF
appExcelFeuille.Cells(X, 1) = rst.Fields("NumContact")
appExcelFeuille.Cells(X, 2) = rst.Fields("NumAssocie")
appExcelFeuille.Cells(X, 3) = rst.Fields("NomPrenomAssocie")
appExcelFeuille.Cells(X, 4) = rst.Fields("Departement")
appExcelFeuille.Cells(X, 5) = rst.Fields("Equipe")
appExcelFeuille.Cells(X, 6) = CStr(rst.Fields("Date"))
appExcelFeuille.Cells(X, 7) = rst.Fields("Categorie")
appExcelFeuille.Cells(X, 8) = rst.Fields("Type")
appExcelFeuille.Cells(X, 9) = rst.Fields("Description")
appExcelFeuille.Cells(X, 10) = rst.Fields("Commentaire")
rst.MoveNext
X = X + 1
Wend
appExcelFeuille.Range("B" & 3) = "Nbr. de contact : " & (X - 5)
'Affichage du rapport.
appExcel.Visible = True
appExcelFeuille.Activate
Exit_ExporteDansRapportParDate:
Exit Sub
Err_ExporteDansRapportParDate:
MsgBox Err.Description
Resume Exit_ExporteDansRapportParDate
End Sub |
Partager