|
-
April 25th, 2001, 07:34 AM
#1
closing and printing an excel worksheet without saving changes
There is a program in Visual Basic that opens an exciting excel 97 worksheet and writes to it. I want my program to write to the excel worksheet print it and close the object without saving the changes. Write now the program opens the excel 97 worksheet, and I have to manualy close the program. And it asks whether to save the changes. So buy just clicking a button in VB, the program should
1) write to the excel worksheet
2) print the worksheet to printer
3) close the worksheet without saving changes.
How do I do this?
Thank You!
-
April 25th, 2001, 09:25 AM
#2
Re: closing and printing an excel worksheet without saving changes
This code works for Excel 2000 not sure about 97.
sub Command1_Click()
dim xlApp as Excel.Application
dim xlBook as Workbook
dim xlSheet as Worksheet
set xlApp = CreateObject("Excel.Application")
set xlBook = xlApp.Workbooks.Open("myBook.xls")
set xlSheet = xlBook.Worksheets(1)
xlSheet.Cells(1, 1) = "Something" 'Write to cell
xlSheet.PrintOut 'print worksheet
xlApp.DisplayAlerts = false 'Do not prompt to save changes
xlBook.Close 'Will close just the workbook
xlApp.Quit 'Will close the entire excel application
set xlSheet = nothing
set xlBook = nothing
set xlApp = nothing
end sub
-K
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
|