Supprimer un fichier excel créé en vbe
Bonjour ,
Le code suivant me permet de créer un fichier grâce à un bout de code en vbe :
Code:
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
| Public Sub pgm_general()
' variable texte
Dim file1 As String
Dim file2 As String
Dim repertoire As String
Dim extension As String
Dim file_ext As String
Dim all_link As String
Dim leaf1 As String
Dim leaf2 As String
' numerique
Dim i As Integer
Dim j As Integer
Dim k As Integer
' application excel
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
' formalisation des liens pour le fichier
repertoire = "D:\"
extension = "xlsx"
file1 = "test_excel"
file_ext = file1 & "." & extension
all_link = repertoire & file_ext
' creation de classeur excel
Set xlApp = CreateObject("Excel.Application") ' creation application excel
xlApp.SheetsInNewWorkbook = 1
Set xlBook = xlApp.Workbooks.Add
xlBook.SaveAs (all_link)
xlApp.Visible = False
Workbooks.Open Filename:=all_link
Set xlBook = xlApp.Workbooks.Add
xlApp.Visible = False
Set xlSheet = xlBook.Worksheets(1)
xlSheet.Name = "onglet1"
Application.DisplayAlerts = False
'xlApp.Quit
'Set xlSheet = Nothing
'Set xlBook = Nothing
'Set xlApp = Nothing
Workbooks(file_ext).Save
Workbooks(file_ext).Close
End Sub |
Mon code vbe se trouve dans un fichier XLSM et est placé dans un module .
Quand le programme est terminé , le fichier "test_excel.xlsx" n'est pas supprimable . Le fichier est utilisé par un autre programme . Dans le gestionnaire des taches , la tache de "test_excel.xlsx" est toujours active.
Quelle instruction dois je ajouter pour que la fermeture soit totale ?
Merci de l'aiguillage ;)