-
Apr 20th, 2018, 11:18 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] How to Close Excel without saving changes?
Very simple as I think
in my project i'm automating a sheet on Excel in the background where Excel is not visible.
I just want after printing that sheet to just close it without saving changes.
and this is my code:
Code:
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
'Here I need to add the code to avoid saving changes
xlApp.Quit()
Me.Close()
-
Apr 20th, 2018, 11:52 AM
#2
Re: How to Close Excel without saving changes?
Make sure you close all of the object appropriately, but in terms of the Workbook (which is the thing that gets saved), try this:
Code:
xlWorkBook.Close (SaveChanges:= False)
-
Apr 21st, 2018, 03:59 AM
#3
Thread Starter
Hyperactive Member
Re: How to Close Excel without saving changes?
Originally Posted by si_the_geek
Make sure you close all of the object appropriately, but in terms of the Workbook (which is the thing that gets saved), try this:
Code:
xlWorkBook.Close (SaveChanges:= False)
Thank you very much
It worked properly and closing the worksheet without saving.
but the thing you were exactly expecting just happened
It's not closing properly and Excel still showing in the Task Manger
Although I was thinking this line of code is enough :
-
Apr 21st, 2018, 04:56 AM
#4
Re: How to Close Excel without saving changes?
Unfortunately it isn't, because Excel is a COM object you need to release it in a more complex way.
I don't have example code handy, but there are several examples on this site, I think this one may be enough for you:
http://www.vbforums.com/showthread.p...n-Task-Manager
-
Apr 21st, 2018, 06:00 AM
#5
Thread Starter
Hyperactive Member
Re: How to Close Excel without saving changes?
Originally Posted by si_the_geek
Unfortunately it isn't, because Excel is a COM object you need to release it in a more complex way.
I don't have example code handy, but there are several examples on this site, I think this one may be enough for you:
http://www.vbforums.com/showthread.p...n-Task-Manager
I checked the site and it was so helpful
What I End up with is just a simple code not the whole complicated process because the end user might need to use Excel again so I made it like this:
from Inside the program after printing for example
Code:
xlWorkBook.Close(SaveChanges:=False)
xlApp.Quit()
xlApp = Nothing
and when closing the form:
Code:
If Not xlApp Is Nothing Then
xlApp = Nothing
End If
Me.Close()
And my problem solved Thank you very very much si_the_geek
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|