Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8
Default code to close an excel sheet without saving it .(via msgbox)


Hi

I have developed some code for Excel application through which i am going to
create an excel appliaction and open a workbook by name "ABC.xls" and insert
a value of 500 in sheet by name "sheet1" in the cell(10,10). Now my
requirement goes some thing like this. I used the code like objexcel.close in
order to close the application without saving it. At that time as we all know
that a small popup message comes up asking for "DO YOU WANT TO SAVE THE
CHANGES FOR BOOK1.XLS" with YES,NO and CANCEL Buttons. so we generally click
either YES OR NO button manually . but i want to click either YES OR NO
Button programatically using VBA OR VB code. Please deem it as urgent. MY
code for this goes some thing like this.



Set fso = CreateObject("Excel.Application")
Set objExcel = fso
Set objWorkBook = objExcel.Workbooks.Open("C:\allfiles.xls")

Set objWorkSheet = objWorkBook.Worksheets("Sheet1")
objWorkSheet.Cells(2, 2).Value = 1500
objExcel.Visible = True
'objWorkBook.Save '(I should not use this line of code)
objWorkBook.Close
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing
Set objWorkSheet = Nothing


Any help is highly appreciated.


Regards,
Vinesh .


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default code to close an excel sheet without saving it .(via msgbox)

Vinesh,

Use the SaveChanges parameter of the close method:

objWorkBook.Close False

or

objWorkBook.Close True

False doesn't save, True does.

HTH,
Bernie
MS Excel MVP


"Satyam Reddy" wrote in message
...

Hi

I have developed some code for Excel application through which i am going to
create an excel appliaction and open a workbook by name "ABC.xls" and insert
a value of 500 in sheet by name "sheet1" in the cell(10,10). Now my
requirement goes some thing like this. I used the code like objexcel.close in
order to close the application without saving it. At that time as we all know
that a small popup message comes up asking for "DO YOU WANT TO SAVE THE
CHANGES FOR BOOK1.XLS" with YES,NO and CANCEL Buttons. so we generally click
either YES OR NO button manually . but i want to click either YES OR NO
Button programatically using VBA OR VB code. Please deem it as urgent. MY
code for this goes some thing like this.



Set fso = CreateObject("Excel.Application")
Set objExcel = fso
Set objWorkBook = objExcel.Workbooks.Open("C:\allfiles.xls")

Set objWorkSheet = objWorkBook.Worksheets("Sheet1")
objWorkSheet.Cells(2, 2).Value = 1500
objExcel.Visible = True
'objWorkBook.Save '(I should not use this line of code)
objWorkBook.Close
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing
Set objWorkSheet = Nothing


Any help is highly appreciated.


Regards,
Vinesh .




  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 320
Default code to close an excel sheet without saving it .(via msgbox)

Change
objWorkbook.Close
to
objWorkbook.Close False

"Satyam Reddy" wrote:


Hi

I have developed some code for Excel application through which i am going to
create an excel appliaction and open a workbook by name "ABC.xls" and insert
a value of 500 in sheet by name "sheet1" in the cell(10,10). Now my
requirement goes some thing like this. I used the code like objexcel.close in
order to close the application without saving it. At that time as we all know
that a small popup message comes up asking for "DO YOU WANT TO SAVE THE
CHANGES FOR BOOK1.XLS" with YES,NO and CANCEL Buttons. so we generally click
either YES OR NO button manually . but i want to click either YES OR NO
Button programatically using VBA OR VB code. Please deem it as urgent. MY
code for this goes some thing like this.



Set fso = CreateObject("Excel.Application")
Set objExcel = fso
Set objWorkBook = objExcel.Workbooks.Open("C:\allfiles.xls")

Set objWorkSheet = objWorkBook.Worksheets("Sheet1")
objWorkSheet.Cells(2, 2).Value = 1500
objExcel.Visible = True
'objWorkBook.Save '(I should not use this line of code)
objWorkBook.Close
objExcel.Quit
Set objWorkBook = Nothing
Set objExcel = Nothing
Set objWorkSheet = Nothing


Any help is highly appreciated.


Regards,
Vinesh .


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Msgbox Code Help Please.... kmwhitt Excel Discussion (Misc queries) 5 September 21st 06 01:52 AM
Am i the first person to close and excel file, without saving chan Cjbrad Excel Discussion (Misc queries) 3 March 2nd 06 07:58 PM
VBA code using if then and msgbox snoopy Excel Discussion (Misc queries) 0 December 1st 05 08:48 PM
Novice - MsgBox Yes/No - Continue if Yes, Close if No Beetlejuice Excel Discussion (Misc queries) 6 August 29th 05 09:48 PM
Excel 2003: File->Close without saving changes (save menu does no. Wai-Yee Excel Discussion (Misc queries) 5 July 25th 05 11:49 PM


All times are GMT +1. The time now is 11:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"