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
| Option Explicit
Dim sOldName As String
Dim sNewName As String
Private Sub Worksheet_Change(ByVal Target As Range)
Dim kR As Long, sOldPath As String, sNewPath As String
If Target.Count > 1 Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target = "" Then Exit Sub
kR = Target.Row
sNewName = Target
If sOldName = "" Then
sOldName = "Classeur" & kR
End If
sOldPath = ThisWorkbook.Path & "\" & sOldName & ".xlsx"
If Dir(sOldPath) = "" Then
MsgBox "Annulé: pas trouvé de fichier nommé " & sOldPath, vbExclamation, "Anomalie"
Application.EnableEvents = False
Target = sOldName
Else
sNewPath = ThisWorkbook.Path & "\" & sNewName & ".xlsx"
If MsgBox("Changer le nom de ce fichier" & vbLf & _
"de " & sOldPath & vbLf & _
"en " & sNewPath, _
vbYesNo, "Oui/Non") = vbYes Then
Name sOldPath As sNewPath
Else
Application.EnableEvents = False
Target = sOldName
End If
End If
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then
sOldName = Target
End If
End Sub |
Partager