Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel won't close in Borland Builder

Status
Not open for further replies.

MichaelDibble

Programmer
Apr 25, 2007
1
GB
Hi

I've managed to write some code to save data to an Excel spreadsheet.

The problem is Excel doesn't close after this function has finished. Using Task manager Excel is still active.

I have found that if I comment out the Worksheet->Connect line, Excel closes properly. As soon as I connect to the worksheet, Excel fails to close.

I'm using the TExcelApplication, TExcelWorkbook, TExcelWorksheet components in C++ Builder 6.

Here is my code...
{
int lcid = LOCALE_USER_DEFAULT;
TVariant vTemplate = EmptyParam;
TVariant vFileName = FileName;
TVariant vSaveChanges = true;

try
{
try
{
ExcelApp->Connect();
}
catch(Exception &exception)
{
::MessageDlg("Excel may not be installed", mtError, TMsgDlgButtons() << mbYes, 0);
Abort;
}

// Set ExcelApp to invisible
ExcelApp->set_Visible(lcid, false);

// Create a new workbook
ExcelApp->Workbooks->Add(vTemplate, lcid);
WorkBook->ConnectTo(ExcelApp->ActiveWorkbook);

// Access the first worksheet
WorkSheet->ConnectTo(WorkBook->ActiveSheet);

// Worksheet access functions

// Disconnect the worksheet
WorkSheet->Disconnect();

// Save then close the WorkBook
WorkBook->Close(vSaveChanges, vFileName, TNoParam(), lcid);
WorkBook->Disconnect();

// Close Excel
ExcelApp->Quit();
ExcelApp->Disconnect();
}
catch(Exception &exception)
{
Application->ShowException(&exception);

WorkSheet->Disconnect();
WorkBook->Disconnect();
ExcelApp->Quit();
ExcelApp->Disconnect();
}

delete WorkSheet;
WorkSheet = NULL;
delete WorkBook;
WorkBook = NULL;
delete ExcelApp;
ExcelApp = NULL;
}

Thank you in advance for your help

Michael Dibble
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top