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
| Dim xlApp As Excel.Application
Dim wbk As Excel.Workbook, blnKillExcelOnExit As Boolean
Dim strXlFile As String
' Obtenir ou créer instance d'Excel.exe
On Error Resume Next
Set xlApp = GetObject(, "Excel.Application")
On Error GoTo 0
If xlApp Is Nothing Then
Set xlApp = New Excel.Application
blnKillExcelOnExit = True
End If
' Ouvrir le classeur
strXlFile = "C:\Mes Documents\LeClasseur.xls"
Set wbk = xlApp.Workbooks.Open(strXlFile)
' Ecrire dans classeur
wbk.Names("Client").RefersToRange(1, 1) = "Toto"
' Sauver et fermer le classeur
wbk.Save
wbk.Close
' Libérer les objets
Set wbk = Nothing
If blnKillExcelOnExit Then xlApp.Quit
Set xlApp = Nothing |