ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing an excel file without saving it.(look through the code ple) (https://www.excelbanter.com/excel-programming/410924-re-closing-excel-file-without-saving-look-through-code-ple.html)

Satyam Reddy

Closing an excel file without saving it.(look through the code ple)
 
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 .

Per Jessen

Closing an excel file without saving it.(look through the code ple)
 
Hi

To close without saveing use line below. To save set SaveChanges:= True

objWorkBook.Close SaveChanges:=False

Regards,
Per

"Satyam Reddy" skrev i meddelelsen
...
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 .



Satyam Reddy

Closing an excel file without saving it.(look through the c
 
hi

thanks for your kind concern on me. The code works well but how to handle
the code programatically once the message box gets popped up. THis type of
requirement i need to handle in my excel application since we have added a
third party add-in for our excel applicatio.


"Per Jessen" wrote:

Hi

To close without saveing use line below. To save set SaveChanges:= True

objWorkBook.Close SaveChanges:=False

Regards,
Per

"Satyam Reddy" skrev i meddelelsen
...
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 .





All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com