Printing Excel sheet

hobbes2103

Active member
Joined
Jul 10, 2003
Messages
43
Hi !

I have a form1 and when i press on button1 i want to open an existing Excel file, i write in it, i print it and then close it without saving changes.

Opening the existing file
Dim xlApp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
xlApp = New Excel.Application
xlbook = xlApp.Workbooks.Open(C:\Model.xls")
xlsheet = xlApp.Sheets(1)
xlsheet.Name = "Hello"

(Then comes all the writing in the sheet)

Printing without saving
xlsheet.PrintOut()
xlApp.Quit()
xlsheet = Nothing
xlbook = Nothing
xlApp = Nothing

Now the problem is that when i execute the program, VB opens the files, writes an prints but when it closes the file i get the usual message from Excel asking me if i want to save the changes in the initial file.
I dont want this message to appear, i want VB to automatically say "No" to it...

How do i do that?

Help is needed urgently... :eek: Thank you!!!!!
 
Try calling xlbook.Close(False) before xlApp.Quit(); the first param is SaveChanges. Havent actually tried it though.
 
Back
Top