Thursday, 27 July 2017
VBA - Excel sometimes fails to close properly
Answer
Answer
I have a macro in outlook, which helps runs statistics in an excel workbook.
However sometimes it fails to close it properly, and ends up ruining the process, since the workbook is open still, when i run it next time.
This is my method for closing it.
Dim xlApp As Object
Dim xlWB As Object
Dim xlSheet As Excel.Worksheet
Set xlApp = New Excel.Application
Set xlWB = xlApp.Workbooks.Open(strpath)
...
xlWB.Save
xlWB.Close savechanges:=True
xlApp.Quit
Set xlApp = Nothing
Set xlWB = Nothing
Set xlSheet = Nothing
From my understanding it should do it.
Answer
Did you turn the displayalerts off? Use:
xlApp.DisplayAlerts = False
after you instanciate the Excel application. That prevents Excel from asking for user input ("are you really sure you want to ...?). Such popup could prevent Excel from closing.
Happened to me more than once on an invisable application.
Subscribe to:
Post Comments (Atom)
casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV
In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...
-
The whole error output being: LNK2019 unresolved external symbol wWinMain referenced in function "int __cdecl __scrt_common_main_seh(vo...
-
I have come across CORS issues multiple times and can usually fix it but I want to really understand by seeing this from a MEAN stack paradi...
-
I recently used canvas to conert images to webp, using : const dataUrl = canvas.toDataURL('image/webp'); But this takes a lots of ti...
No comments:
Post a Comment