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
| Private Sub btnLancer_Click(sender As System.Object, e As System.EventArgs) Handles btnLancer.Click
Dim fichier As String
fichier = "C:\fichier.xls"
'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
'Ouverture de l'application
appExcel = GetObject(, "Excel.Application")
'Récupération du classeur par défaut
wbExcel = appExcel.Workbooks.Open(fichier)
'Récupération de la feuille
wsExcel = wbExcel.Worksheets.Item(3)
wbExcel.Close() 'Fermeture du classeur Excel
appExcel.Quit() 'Fermeture de l'application Excel
'Désallocation mémoire
wsExcel = Nothing
wbExcel = Nothing
appExcel = Nothing
End Sub |