Ouvrir fichier excel en vba
Bonjour à tous,
Je voudrai faire un programme vba capable d'aller chercher des infos dans un classeur excel fermé situé sur le disque dur et que les données de ce classeur ce "colle" dans un autre fichier excel.
En clair, j'ai mon fichier "MC_essai" qui doit aller prendre des infos dans le fichier excel "MC_Plastique" et coller les infos de "MC_Plastique" dans "MC_essai" Cependant, je veux récupérer que les infos concernant un N° de semaine précis. Et je n'arrive pas à faire ce dernier point.
Quelqu'un pourrait il regarder mon programme et me dire ce qui ne va pas svp!
Merci, par avance, pour votre aide
Rob's
Mon programme:
Code:
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| Dim newRecord As Long
Dim Date_D As Date
Private Sub Annuler_Click()
Unload Me
newRecord = Range("A" & Rows.Count).End(xlUp)(2).Row
Rows(newRecord).Select
Call viderFormulaire
End Sub
Private Sub UserForm_Activate()
Call chargerListes
End Sub
Private Sub Valider_Click()
' Champs obligatoires
If Atelier.Text = "" Then
MsgBox "Le champs Atelier n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
If N°Semaine.Text = "" Then
MsgBox "Le champs N°Semaine n'a pas été rempli. Veuillez le remplir.", vbOKOnly + vbInformation, "Champs manquants ou incorrects"
Exit Sub
End If
' Récupération des données dans classeur fermé
Workbooks("MC_essai.xlsm").Worksheets("Saisie").Cells.ClearContents
Workbooks.Open Filename:="\\Gpao\commun\30_QUALITE\\307_Gestion_de_service\Main_courante_atelier\MC_Plastique.xlsm"
Workbooks("MC_Plastique.xlsm").Worksheets("Synthese").Cells.Copy _
Workbooks("MC_essai.xlsm").Worksheets("Saisie").Range("A1")
Workbooks("MC_Plastique.xlsm").Close False
UserForm1.Hide
End Sub
Private Sub chargerListes()
'Défauts par l'atelier
UserForm1.Atelier.AddItem "Contrôle SF-A"
UserForm1.Atelier.AddItem "Débit"
UserForm1.Atelier.AddItem "Expédition"
UserForm1.Atelier.AddItem "Finition"
UserForm1.Atelier.AddItem "Metal"
UserForm1.Atelier.AddItem "Plastique"
UserForm1.Atelier.AddItem "Qualité"
UserForm1.Atelier.AddItem "Luxe"
UserForm1.Atelier.AddItem "Réception Fournisseur"
UserForm1.Atelier.AddItem "Responsable Qualité"
UserForm1.Atelier.AddItem "Shootage"
UserForm1.Atelier.AddItem "Tri branches"
UserForm1.Atelier.AddItem "Tri faces"
UserForm1.Atelier.AddItem "TS"
UserForm1.Atelier.AddItem "Witech"
End Sub
Private Sub viderFormulaire()
Atelier.Text = ""
N°Semaine.Text = ""
End Sub
Private Sub tracerBordures(ByVal Ligne As Long)
Range(Cells(Ligne, 1), Cells(Ligne, 15)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = 1
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = 1
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = 1
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = 1
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub |