Outils logiciels pour les cours Paris II
Cours Paris II
Stages/ Thèses/ Séminaires |
Cours 4Introduction à VBA Visual Basic: langage interprété pour:
Mise en place
Modèle impératif
Type de variables
Types de données
Fonctions de base
Développement
Exemples:
Sub b()
Sub a1() Dim i, n As Integer n = 5 i = 1 Do While i <= n Cells(i, i) = i i = i + 1 Loop End Sub Sub a2() Dim i, n As Integer n = 5 i = 1 For i = 1 To n Cells(i, i + 5) = i Next i End Sub Sub a3() Dim i, j, n As Integer n = 5 i = 1 j = 1 Do While j <= n For i = 1 To n Cells(i, j) = i + j Next i j = j + 1 Loop End Sub
Sub a4() Dim i, j, k, n As Integer n = 5 i = 1 j = 1 Do While j <= n For i = 1 To n k = (i + j) Mod 2 If k = 0 Then Cells(i, j) = 0 Else Cells(i, j) = 1 End If Next i j = j + 1 Loop End Sub
Private Sub c() Range("B1") = 1 Cells(2,2)=2 End Sub Public Sub ShowTime1() Range("C1") = Now() End Sub
Sub drawcell() Range("A10").Select With Selection.Interior .ColorIndex = 6 .Pattern = xlSolid End With Range("A11").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid End With End Sub Sub a5() ' Test si i+j est pair ou impair ' Couleurs bleu=5 rouge=3 blanc=2 Dim i, j, k, n As Integer n = 5 i = 1 j = 1 Do While j <= n For i = 1 To n k = (i + j) Mod 2 If k = 0 Then Cells(i, j).Select With Selection.Interior .ColorIndex = 6 .Pattern = xlSolid End With Else Cells(i, j).Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid End With End If Next i j = j + 1 Loop End Sub
Sub test() Dim str As String str = "hello" & Chr(13) & chr(13) & "world" MsgBox str End Sub |