Bonjour,
J'ai un code qui, quand il est affecté à un commandButton, fonctionne très bien.
J'ai essayé de l'affecté à une image et du coup, il fonctionne toujours mais ne tient plus compte des données du classeur d'origine, mais uniquement du classeur "main courante"
Je comprend vraiment pas pourquoi
Le code en question:
Sub Image10_Clic()
If Range("F7").Value = "" Or Range("F9").Value = "" Or Range("F11").Value = "" Or Range("F13").Value = "" Or Range("F14").Value = "" Then
MsgBox "Certaines données sont manquantes (gestionnaire, nom de l'aire, date,...)"
Else
Dim iNum%, iLn%, dossier$
Dim feuille As String
feuille = Year(Date)
Application.ScreenUpdating = False
dossier = Range("F9") & "_" & Range("F11") & "_" & Year(Date) & "_" & "CA"
Workbooks.Open Filename:=ThisWorkbook.Path & "\main courante.xlsm"
With Workbooks("main courante.xlsm").Sheets(feuille)
iNum = Application.CountIf(.Range("F:F"), "=*" & dossier & "*")
If iNum > 0 Then dossier = dossier & Format(iNum, "00")
iLn = .Range("A" & .Rows.Count).End(xlUp).Row + 1
.Cells(iLn, 1) = CDate(Range("F14")) 'Date
.Cells(iLn, 2) = Range("F7") 'Gestionnaire
.Cells(iLn, 3) = Range("F9") 'Nom aire
.Cells(iLn, 4) = "Contrôle Annuel" 'Libellé
.Cells(iLn, 5) = Range("F13") 'Intervenant
.Cells(iLn, 6) = dossier
End With
Workbooks("main courante.xlsm").Save
Workbooks("main courante.xlsm").Close
For Each sh In ThisWorkbook.Worksheets
sh.TextBox1.Value = dossier
Next sh
End If
End Sub
Merci pour l'aide