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
| Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim nomdossier As String, chemin As String, Fichier As String, nomfichier As String
Dim i, j, DernièreLigne, DernièreColonne
'----------------------------------------------------------------------------------------------
nomdossier = "Archive des BD"
nomfichier = "Historique des connexions" & ".csv"
chemin = ThisWorkbook.Path
ChDir chemin 'se place sur le repertoire du programme
If Dir(chemin & "\" & nomdossier & "\", vbDirectory) = "" Then
MkDir chemin & "\" & nomdossier
End If
repert = chemin & "\" & nomdossier
ChDir repert
Fichier = repert & "\" & nomfichier
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Application.ScreenUpdating = False
With Sheets("Connexion")
.Visible = True
.Activate
'On Error Resume Next
'SetAttr Fichier, vbNormal
Open nomfichier For Output As #1 'Tu crées le fichier
DernièreColonne = .Range("A1").End(xlToRight).Column
DernièreLigne = .Cells(1, 1).SpecialCells(xlCellTypeLastCell).Row '- 1
For i = 1 To DernièreLigne
For j = 1 To DernièreColonne ' - 1
Print #1, Cells(i, j).Value, ";";
Next j
Print #1, Cells(i, j + 1).Value
Next i
Close #1
'SetAttr Fichier, vbReadOnly
.Visible = False
End With
Sheets("Menu").Activate
Application.ScreenUpdating = True
End Sub |
Partager