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
| Option Explicit
Private strTableOfURLs(1 To 10) As String
Private Sub Form_Load()
' Déclaration des variables nécessaires pour lire dans un fichier Excel.
Dim xl As New Excel.Application ' une variable pour Excel,
Dim wb As Excel.Workbook ' une variable pour le classeur,
Dim ws As Excel.Worksheet ' une variable pour la feuille de calcul
' et une variable objet Range pour la boucle For Each...
Dim cellule As Excel.Range
Dim i As Integer ' compteur d'indice du tableau strTableOfURLs
i = 1 ' initialisation du compteur
Set wb = xl.Workbooks.Open(App.Path & "\URLs.xls") ' ouverture du fichier
' ce classeur contient une plage nommée 'urls'
' dans la feuille nommée 'adresse'
Set ws = wb.Sheets("adresses")
For Each cellule In ws.Range("urls")
strTableOfURLs(i) = CStr(cellule.Value) ' on s'assure d'avoir une 'string'
i = i + 1 ' incrémentation de l'indice du tableau
Next
wb.Close ' fermeture du fichier
xl.Quit ' fermeture de l'application Excel
Set ws = Nothing ' les variables objet sont virées de la mémoire (flushed)
Set wb = Nothing
Set xl = Nothing
'
' Paramètres du Timer
With Timer1
.Interval = 10000 ' une seconde (10000 ms. = 10 sec.)
.Enabled = True ' démarré (started)
End With
End Sub
Private Sub Form_Activate()
' désactive le textBox txtSctiveURL et le bouton de navigation
txtActiveURL.Locked = True
txtActiveURL.TabStop = False
cmdNavigate.Enabled = False
' Affiche une page pour éviter l'affichage
' d'un message d'erreur dans le WebBrowser
wbrAffichage.Navigate strTableOfURLs(10)
txtActiveURL.Text = strTableOfURLs(10)
End Sub
Private Sub cmdStopTimer_Click()
' Arrêt du timer
Timer1.Enabled = False
' Activation du champ d'adresse et du bouton de navigation
txtActiveURL.Locked = False
txtActiveURL.TabStop = True
cmdNavigate.Enabled = True
' donne le focus au champ url et sélectionne son contenu
With txtActiveURL
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
End Sub
Private Sub cmdNavigate_Click()
wbrAffichage.Navigate txtActiveURL.Text
End Sub
Private Sub cmdQuitter_Click()
End
End Sub
Private Sub Timer1_Timer()
Static i As Integer ' static makes it keaping its value
i = i + 1 ' initialize to 1 as first index of the private global table of urls
i = IIf(i = 10, 1, i) ' use the IIF function to set conditional value to a variable
txtActiveURL.Text = strTableOfURLs(i)
wbrAffichage.Navigate strTableOfURLs(i)
End Sub |
Partager