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
| Private Sub Command1_Click()
'Déclaration des variables
Dim appExcel As excel.Application 'Application Excel
Dim wbExcel As excel.Workbook 'Classeur Excel
Dim wsExcel As excel.Worksheet 'Feuille Excel
Dim K As Integer
Set appExcel = CreateObject("Excel.Application")
appExcel.Visible = True
appExcel.Workbooks.Open ("F:\Documents\test.xlsx")
Set wbExcel = appExcel.ActiveWorkbook
Set wsExcel = wbExcel.ActiveSheet
'Test si la 1ère ligne est vide
Range("A1").Select
If (IsEmpty(ActiveCell)) Then
Range("A1").Select
ActiveCell.FormulaR1C1 = "Nom"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Prénom"
Range("C1").Select
ActiveCell.FormulaR1C1 = "N° tél fixe"
Range("D1").Select
ActiveCell.FormulaR1C1 = "N° tél mobile"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Adresse"
Range("F1").Select
ActiveCell.FormulaR1C1 = "Problèmes"
Range("G1").Select
ActiveCell.FormulaR1C1 = "Date"
End If
'test pour déterminer quelle ligne est inoccupée
K = 2
While (Range("A" & K) <> "")
K = K + 1
Wend
'transfert des données saisies dans le classeur excel
Range("A" & K).Select
ActiveCell.FormulaR1C1 = Nom.Text
Range("B" & K).Select
ActiveCell.FormulaR1C1 = Prenom.Text
Range("C" & K).Select
ActiveCell.FormulaR1C1 = TelFixe.Text
Range("D" & K).Select
ActiveCell.FormulaR1C1 = TelMobile.Text
Range("E" & K).Select
ActiveCell.FormulaR1C1 = Adresse.Text
Range("F" & K).Select
ActiveCell.FormulaR1C1 = "Le " & Date & " à " & Time
ActiveWorkbook.Save
wbExcel.Close 'Fermeture du classeur Excel
appExcel.Quit
Set wsExcel = Nothing
Set wbExcel = Nothing
Set appExcel = Nothing
'on efface les données saisies
Nom.Text = "Nom"
Prenom.Text = "Prénom"
TelFixe.Text = "N° tél fixe"
TelMobile.Text = "N° tél mobile"
Adresse.Text = "Adresse"
Prob.Text = ""
End Sub |
Partager