Maintenant je souhaiterais mettre le macro sur un fichier excel et faire la recherche sur un autre fichier sans l'ouvrir.
J'ai essayé ce code mais j'ai des erreurs.
Option Explicit
Private Sub CommandButton1_Click()
' bouton recherche
Dim lig&
Dim sel As Range
Dim sel1 As Range
Dim sel2 As Range
Dim fin As Long
Dim appXl As Excel.Application
Set appXl = CreateObject("Excel.Application")
With appXl
.Workbooks.Open ("D:\Users\Mosow\Desktop\SUIVI CAFF\suiviCAF2018.xlsm")
.Visible = False
End With
fin = Worksheets.Range("Etude en cours").UsedRange.Rows.Count
With Worksheets("Etude en cours").Range("D" & fin)
Set sel = .Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole)
'Set sel1 = Sheets("Etudes finies").Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole)
'Set sel2 = Sheets("Etudes archivees").Cells.Find(Me.TextBox1.Value, , xlValues, xlWhole)
If sel Is Nothing Then
MsgBox "Ce dossier n'est pas en étude ce jour pour Scopelec"
Else
lig = Feuil1.Columns("D").Find(TextBox1.Value, , xlValues, xlWhole).Row
MsgBox "COMMENTAIRE CAFF:" & Feuil1.Cells(lig, 15).Value
End If
End With
Set sel = Nothing
appXl.Workbooks("suiviCAF2018.xlsm").Close
Set appXl = Nothing
End Sub
Private Sub CommandButton2_Click()
Unload Me 'permet de fermer le formulaire
End Sub