Board index » delphi » Code for Excel 2002 not working for Excel 2003

Code for Excel 2002 not working for Excel 2003


2006-02-07 03:57:19 PM
delphi144
Hi,
Looking to earlier threads about Excel 2003, and if I did not miss
something, I couldn't find a hint about how to bring my old OLE code working
with Excel 2003.
With Excel 2002 I did sucessfully:
m_ExcelIntf := TExcelApplication.Create( nil );
try
m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
except
m_ExcelIntf.Free;
m_ExcelIntf := nil;
MessageDlg( 'Please, close first the current Excel instance', mtError,
[mbOK],0);
Exit;
end;
// Create a new workbook
m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
// Activate the workbook
m_Workbook.Activate(0);
This code does not work with Excel 2003 (by two of my customer). Does anyone
know a solution?
Thanks,
Hubert
 
 

Re:Code for Excel 2002 not working for Excel 2003

Hi,
I did the following with your code:
var
m_ExcelIntF : TExcelApplication;
m_workbook: _WorkBook;
begin
lcid:=LOCALE_USER_DEFAULT;//added this
m_ExcelIntf := TExcelApplication.Create( nil );
try
m_ExcelIntf.Visible[lcid]:=True;//added this
m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
except
m_ExcelIntf.Free;
m_ExcelIntf := nil;
MessageDlg( 'Please, close first the current Excel instance', mtError,
[mbOK],0);
Exit;
end;
// Create a new workbook
m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
// Activate the workbook
m_Workbook.Activate(lcid);//added lcid as inparameter here
Im not sure about how you declared you m_Workbook, but this code works on my
office2003
Best Regards,
Johan Ingemansson
"Hubert Rétif" <XXXX@XXXXX.COM>writes
Quote
Hi,

Looking to earlier threads about Excel 2003, and if I did not miss
something, I couldn't find a hint about how to bring my old OLE code
working
with Excel 2003.

With Excel 2002 I did sucessfully:

m_ExcelIntf := TExcelApplication.Create( nil );
try
m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
except
m_ExcelIntf.Free;
m_ExcelIntf := nil;
MessageDlg( 'Please, close first the current Excel instance', mtError,
[mbOK],0);
Exit;
end;
// Create a new workbook
m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
// Activate the workbook
m_Workbook.Activate(0);

This code does not work with Excel 2003 (by two of my customer). Does
anyone
know a solution?

Thanks,
Hubert


 

Re:Code for Excel 2002 not working for Excel 2003

Thanks a lot Johan.
In which unit is LOCALE_USER_DEFAULT declared? or which value does it have?
I am using Delphi 7 Architect.
Thanks,
Hubert.
"Johan Ingemansson" <XXXX@XXXXX.COM>schrieb im
Newsbeitrag news:XXXX@XXXXX.COM...
Quote
Hi,

I did the following with your code:
var
m_ExcelIntF : TExcelApplication;
m_workbook: _WorkBook;
begin
lcid:=LOCALE_USER_DEFAULT;//added this
m_ExcelIntf := TExcelApplication.Create( nil );
try
m_ExcelIntf.Visible[lcid]:=True;//added this
m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
except
m_ExcelIntf.Free;
m_ExcelIntf := nil;
MessageDlg( 'Please, close first the current Excel instance', mtError,
[mbOK],0);
Exit;
end;
// Create a new workbook
m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
// Activate the workbook
m_Workbook.Activate(lcid);//added lcid as inparameter here

Im not sure about how you declared you m_Workbook, but this code works on
my
office2003

Best Regards,

Johan Ingemansson


"Hubert Rétif" <XXXX@XXXXX.COM>writes
news:43e852dd$XXXX@XXXXX.COM...
>Hi,
>
>Looking to earlier threads about Excel 2003, and if I did not miss
>something, I couldn't find a hint about how to bring my old OLE code
>working
>with Excel 2003.
>
>With Excel 2002 I did sucessfully:
>
>m_ExcelIntf := TExcelApplication.Create( nil );
>try
>m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
>except
>m_ExcelIntf.Free;
>m_ExcelIntf := nil;
>MessageDlg( 'Please, close first the current Excel instance',
mtError,
>[mbOK],0);
>Exit;
>end;
>// Create a new workbook
>m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
>// Activate the workbook
>m_Workbook.Activate(0);
>
>This code does not work with Excel 2003 (by two of my customer). Does
>anyone
>know a solution?
>
>Thanks,
>Hubert
>
>


 

Re:Code for Excel 2002 not working for Excel 2003

In between I have found it: Windows.
All is working fine now. Thanks a lot again.
Hubert
"Hubert Rétif" <XXXX@XXXXX.COM>schrieb im Newsbeitrag
Quote
Thanks a lot Johan.

In which unit is LOCALE_USER_DEFAULT declared? or which value does it
have?

I am using Delphi 7 Architect.

Thanks,
Hubert.

"Johan Ingemansson" <XXXX@XXXXX.COM>schrieb im
Newsbeitrag news:XXXX@XXXXX.COM...
>Hi,
>
>I did the following with your code:
>var
>m_ExcelIntF : TExcelApplication;
>m_workbook: _WorkBook;
>begin
>lcid:=LOCALE_USER_DEFAULT;//added this
>m_ExcelIntf := TExcelApplication.Create( nil );
>try
>m_ExcelIntf.Visible[lcid]:=True;//added this
>m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
>except
>m_ExcelIntf.Free;
>m_ExcelIntf := nil;
>MessageDlg( 'Please, close first the current Excel instance',
mtError,
>[mbOK],0);
>Exit;
>end;
>// Create a new workbook
>m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
>// Activate the workbook
>m_Workbook.Activate(lcid);//added lcid as inparameter here
>
>Im not sure about how you declared you m_Workbook, but this code works
on
my
>office2003
>
>Best Regards,
>
>Johan Ingemansson
>
>
>"Hubert Rétif" <XXXX@XXXXX.COM>writes
>news:43e852dd$XXXX@XXXXX.COM...
>>Hi,
>>
>>Looking to earlier threads about Excel 2003, and if I did not miss
>>something, I couldn't find a hint about how to bring my old OLE code
>>working
>>with Excel 2003.
>>
>>With Excel 2002 I did sucessfully:
>>
>>m_ExcelIntf := TExcelApplication.Create( nil );
>>try
>>m_ExcelIntf.SheetsInNewWorkBook[0] := 1;
>>except
>>m_ExcelIntf.Free;
>>m_ExcelIntf := nil;
>>MessageDlg( 'Please, close first the current Excel instance',
mtError,
>>[mbOK],0);
>>Exit;
>>end;
>>// Create a new workbook
>>m_Workbook := m_ExcelIntf.Workbooks.Add(Null, 0);
>>// Activate the workbook
>>m_Workbook.Activate(0);
>>
>>This code does not work with Excel 2003 (by two of my customer). Does
>>anyone
>>know a solution?
>>
>>Thanks,
>>Hubert
>>
>>
>
>