Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default closing excel file through code

Hi,



I am using Excel for reporting. For opening excel file I have write code :



exlApp = null;

exlApp = new ApplicationClass();

//try

//{

object missing = System.Reflection.Missing.Value;

string path = oString();

excelWorkbook = exlApp.Workbooks.Open(path, missing,

1,

missing,

Excel.XlTextQualifier.xlTextQualifierNone,

missing,

missing,

missing,

true, //COMMA

missing,

missing,

missing,

missing

);

path = "";

path = ();

path = path + @"\" + frmSiteName.siteName + " GenSumm " + DateTime.Now.Day +
"_" + DateTime.Now.Month + "_" + DateTime.Now.Year + " " + DateTime.Now.Hour
+ "." + DateTime.Now.Minute + ".csv";

excelWorkbook.SaveAs(path, missing, missing, missing, missing, missing,
XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing);

object pwd = "cgclogic";

excelWorkbook.Unprotect(pwd);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Log Report");

excelWorksheet.Unprotect(pwd);







And before that form termination, write code :

excelWorkbook.Save();

exlApp.Workbooks.Close();


exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;



This form is opening through MDI.



But even after form close 'Windows Task Manager' is showing 'Excel' in
process.
And after application colse it is removing from task manager.

When that file in the reports folder try to open, it is giving error : "
This file is already opened . DO you want to reopen the file ?" or " This
file is being modified by other user . Open a read-only copy."



please tell how to close that file using code.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default closing excel file through code

Only a guess but try changing

exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;


to -

excelWorksheet = null;

ensure all unsaved wb's are closed, after saving or with close false
excelWorkbook = null;
exlApp.Quit();
exlApp = null;

Regards,
Peter T


"Namrata" wrote in message
...
Hi,



I am using Excel for reporting. For opening excel file I have write code :



exlApp = null;

exlApp = new ApplicationClass();

//try

//{

object missing = System.Reflection.Missing.Value;

string path = oString();

excelWorkbook = exlApp.Workbooks.Open(path, missing,

1,

missing,

Excel.XlTextQualifier.xlTextQualifierNone,

missing,

missing,

missing,

true, //COMMA

missing,

missing,

missing,

missing

);

path = "";

path = ();

path = path + @"\" + frmSiteName.siteName + " GenSumm " + DateTime.Now.Day

+
"_" + DateTime.Now.Month + "_" + DateTime.Now.Year + " " +

DateTime.Now.Hour
+ "." + DateTime.Now.Minute + ".csv";

excelWorkbook.SaveAs(path, missing, missing, missing, missing, missing,
XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing);

object pwd = "cgclogic";

excelWorkbook.Unprotect(pwd);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Log Report");

excelWorksheet.Unprotect(pwd);







And before that form termination, write code :

excelWorkbook.Save();

exlApp.Workbooks.Close();


exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;



This form is opening through MDI.



But even after form close 'Windows Task Manager' is showing 'Excel' in
process.
And after application colse it is removing from task manager.

When that file in the reports folder try to open, it is giving error : "
This file is already opened . DO you want to reopen the file ?" or " This
file is being modified by other user . Open a read-only copy."



please tell how to close that file using code.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default closing excel file through code

Thanks for reply !
I change the code as:
excelWorksheet = null;

ensure all unsaved wb's are closed, after saving or with close false
excelWorkbook = null;
exlApp.Quit();
exlApp = null;


But excel file still remains open.

"Peter T" wrote:

Only a guess but try changing

exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;


to -

excelWorksheet = null;

ensure all unsaved wb's are closed, after saving or with close false
excelWorkbook = null;
exlApp.Quit();
exlApp = null;

Regards,
Peter T


"Namrata" wrote in message
...
Hi,



I am using Excel for reporting. For opening excel file I have write code :



exlApp = null;

exlApp = new ApplicationClass();

//try

//{

object missing = System.Reflection.Missing.Value;

string path = oString();

excelWorkbook = exlApp.Workbooks.Open(path, missing,

1,

missing,

Excel.XlTextQualifier.xlTextQualifierNone,

missing,

missing,

missing,

true, //COMMA

missing,

missing,

missing,

missing

);

path = "";

path = ();

path = path + @"\" + frmSiteName.siteName + " GenSumm " + DateTime.Now.Day

+
"_" + DateTime.Now.Month + "_" + DateTime.Now.Year + " " +

DateTime.Now.Hour
+ "." + DateTime.Now.Minute + ".csv";

excelWorkbook.SaveAs(path, missing, missing, missing, missing, missing,
XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing);

object pwd = "cgclogic";

excelWorkbook.Unprotect(pwd);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Log Report");

excelWorksheet.Unprotect(pwd);







And before that form termination, write code :

excelWorkbook.Save();

exlApp.Workbooks.Close();


exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;



This form is opening through MDI.



But even after form close 'Windows Task Manager' is showing 'Excel' in
process.
And after application colse it is removing from task manager.

When that file in the reports folder try to open, it is giving error : "
This file is already opened . DO you want to reopen the file ?" or " This
file is being modified by other user . Open a read-only copy."



please tell how to close that file using code.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default closing excel file through code

Are all your object variables released in opposite order to which they were
referenced.

Just for testing, make the instance visible
exlApp.visible = true

close all workbooks and release your objects

do not do exlApp.Quit

Do you have any workbooks open, if so why, eg, xl is waiting for user to
dismiss some message perhaps
also check for any hidden workbooks, alt-F11 and look in projects panel in
the VBE

Manually quit
Is your workbook still open

If no workbooks are open, repeat with Quit and destroy your exlApp

Regards,
Peter T

"Namrata" wrote in message
...
Thanks for reply !
I change the code as:
excelWorksheet = null;

ensure all unsaved wb's are closed, after saving or with close false
excelWorkbook = null;
exlApp.Quit();
exlApp = null;


But excel file still remains open.

"Peter T" wrote:

Only a guess but try changing

exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;


to -

excelWorksheet = null;

ensure all unsaved wb's are closed, after saving or with close false
excelWorkbook = null;
exlApp.Quit();
exlApp = null;

Regards,
Peter T


"Namrata" wrote in message
...
Hi,



I am using Excel for reporting. For opening excel file I have write

code :



exlApp = null;

exlApp = new ApplicationClass();

//try

//{

object missing = System.Reflection.Missing.Value;

string path =

oString();

excelWorkbook = exlApp.Workbooks.Open(path, missing,

1,

missing,

Excel.XlTextQualifier.xlTextQualifierNone,

missing,

missing,

missing,

true, //COMMA

missing,

missing,

missing,

missing

);

path = "";

path = ();

path = path + @"\" + frmSiteName.siteName + " GenSumm " +

DateTime.Now.Day
+
"_" + DateTime.Now.Month + "_" + DateTime.Now.Year + " " +

DateTime.Now.Hour
+ "." + DateTime.Now.Minute + ".csv";

excelWorkbook.SaveAs(path, missing, missing, missing, missing,

missing,
XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing);

object pwd = "cgclogic";

excelWorkbook.Unprotect(pwd);

Excel.Sheets excelSheets = excelWorkbook.Worksheets;

excelWorksheet = (Excel.Worksheet)excelSheets.get_Item("Log Report");

excelWorksheet.Unprotect(pwd);







And before that form termination, write code :

excelWorkbook.Save();

exlApp.Workbooks.Close();


exlApp.Quit();

exlApp = null;

excelWorksheet = null;

excelWorkbook = null;



This form is opening through MDI.



But even after form close 'Windows Task Manager' is showing 'Excel' in
process.
And after application colse it is removing from task manager.

When that file in the reports folder try to open, it is giving error :

"
This file is already opened . DO you want to reopen the file ?" or "

This
file is being modified by other user . Open a read-only copy."



please tell how to close that file using code.






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
Re-show userform after closing file - code help Gerry O Excel Discussion (Misc queries) 3 September 4th 07 10:52 PM
How to code on Macro on saving and closing a file? Eric Excel Worksheet Functions 1 June 10th 07 01:32 PM
code for closing out an excel file while in the browser? Tom Excel Programming 1 September 2nd 06 08:35 PM
Macro Code for closing excel... Bonbon[_4_] Excel Programming 5 April 12th 06 12:57 PM
Problems closing Excel correctly by code Filips Benoit Excel Programming 2 June 29th 05 01:37 PM


All times are GMT +1. The time now is 09:23 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"