Set xlApplication = CreateObject("Excel.Application")
xlApplication.Visible = True
DoEvents
Set xlWorkBook = xlApplication.Workbooks
xlWorkBook.Add
Set xlFeuilEnse = xlApplication.ActiveSheet
DoEvents
'Création et renommage des feuilles
Set xlFeuilMeca = xlApplication.Sheets.Add(After:=Worksheets(Worksheets.Count))
Set xlFeuilComm = xlApplication.Sheets.Add(After:=Worksheets(Worksheets.Count))
xlFeuilEnse.Name = "ENSEMBLES"
xlFeuilMeca.Name = "PIECES MECANIQUES"
xlFeuilComm.Name = "ELEMENTS DU COMMERCE"
Hello
I'm making a macro to create an excel file and add information to it. I have a problem with the creation of the excel file.
Macro works 1 time out of 2 and 1 time out of 2 strictly. It's in my creation of my file that I think there is a problem but I looked on the net and I found nothing.
Can anyone help me?
Here is my snippet of code for the creation of the excel file:
I may have had the same problem recently, look at the processes, after using your macro if excel is still in use it means that you do not completely close the process and it goes wrong on the second launch
Sub FermetureExcel()
Set xlFeuilMeca = Nothing
Set xlFeuilComm = Nothing
'Fermeture du classeur et de Excel
oXL.DisplayAlerts = False
oXL.Workbooks.Close
oXL.Quit
oXL.DisplayAlerts = True
'Désallocation de la mémoire
Set oSH = Nothing
Set oWB = Nothing
Set oXL = Nothing
End Sub
If you restart the macro and it's still on the same file it can't create the page 'SETS', 'MECHANICAL PARTS' and 'COMMERCIAL ITEMS' twice
Put a condition, if the page doesn't exist it is created.
Your macro fills your excel file every time you click following the assembly that is open, you create/open a new excel file every time you store all the information on a single file?
I know it's an unreleased excel resource issue. I tried to close my excel file via excel when my macro is finished and restart my macro but I still have the same problem.
Is there a test that allows you to know if the resource is released and if not released from freeing it?
You have to look in the processes, once you have closed the excel go to your task manager (Ctrl + SHIFT + Esc) -> Process and check that there is no EXCEL.EXE
Set xlMeca Sheet = xlApplication.Sheets.Add(After:=Worksheets(Worksheets.Count)) Set xlSheetComm = xlApplication.Sheets.Add(After:=Worksheets(Worksheets.Count))