Board index » delphi » Work with Excel 97 AND 2000??

Work with Excel 97 AND 2000??

Hi,

My app needs to be able to do some simple (?) stuff with Excel, and it needs
to work with Excel 97 "or later." I.e., it absolutely has to work with Excel
97 and 2000, and we'll deal with newer versions as they appear. I'm using
Delphi 4.03, and it's not likely we'll upgrade to D5 soon enough to be of
any help.

In order to work with multiple versions, DO I HAVE TO USE "LATE BINDING"?? I
have done everything I need using the EXCEL8.OLB type library, not realizing
until the end that it wouldn't work with Excel 2000. How can I translate
that into something that works with different versions of Excel?

I do NOT have a good grasp of the different ways to do COM stuff.
(Interface, Dispinterface, OleVariant.) I'm busily reading everything I can
find, including D. Pate's stuff and D4DG (Pacheco/Texeira) chapter 23, but I
would really appreciate some quick lessons.

The app needs to:
- Open a delimited text file, with specific field-formatting requirements.
Currently, with early binding, I'm using the OpenText method and providing
the FieldInfo array.
- Move a worksheet from one workbook to another.
- Open an existing .XLS file and run a macro.
- Set Excel free so that the user can continue editing, etc., as long as he
likes. Once set free, my app doesn't need to know what else happens.
- Change Visible, DisplayAlerts and other such things appropriately.
As I said, I've figured out how to do all the above via the Excel8 type
library, but have no idea how to make it version-independent.

Many thanks,

Julian Slade

 

Re:Work with Excel 97 AND 2000??


"Julian L. Slade" <slad...@acwilm.com> skrev i melding
news:8dijs5$m4a2@bornews.borland.com...

Quote

> My app needs to be able to do some simple (?) stuff with Excel, and it
needs
> to work with Excel 97 "or later." I.e., it absolutely has to work with
Excel
> 97 and 2000, and we'll deal with newer versions as they appear. I'm using
> Delphi 4.03, and it's not likely we'll upgrade to D5 soon enough to be of
> any help.

> In order to work with multiple versions, DO I HAVE TO USE "LATE BINDING"??
I
> have done everything I need using the EXCEL8.OLB type library, not
realizing
> until the end that it wouldn't work with Excel 2000. How can I translate
> that into something that works with different versions of Excel?

Hi !

I had the same problem one month ago, and got helped in this NG. Below is my
response the day I actually got it working:

Good luck !

<<"Deborah Pate" <d.p...@cableinet.co.not-this-bit.uk> skrev i melding
news:38df1e84@dnews...

Quote
> <<Bjoerge Saether:
> One Range-method is declared differently in '97 and '2000
> versions of Excel:

> If you don't need to set the parameters, you could just use
> the 2000 version - it works with Excel 97.

I just commented out the last 3(4, that should be) parameters of the Replace
method in '97 TLB,
and -voil ! It worked !
Thanks a lot !

Quote
>I think this is
> another internationalization thing - if you look up the Excel
> 97 VBA help, you'll see it knows nothing about the extra
> parameters.

Both my Excel versions are Norwegian, but the extra params are not described
in the Norwegian help file, either.  I just added them to satisfy the
compiler...but now they're gone..;-)

Quote
> But the 97 sort method has 3 similar parameters
> at the end, which according to the help are not used in US
> English Excel versions, and which don't appear in
> Excel2000.pas. Does the 2000 help say anything about
> international users?

No. The enclosed VBA help file is English in '2000, while Norwegian in '97.>>

--
Bjoerge Saether
Consultant / Developer
Asker, Norway
bsaether.removet...@online.no (remove the obvious)

Re:Work with Excel 97 AND 2000??


Bj?rge,

Thanks for your response.

In my case, the method I seem to be having problems with is
Workbooks.OpenText. The declaration in Excel 2000 has 2 additional
parameters (DecimalSeparator and ThousandsSeparator).

If I use Excel 97's TLB, it doesn't work with Excel 2000. My first call to
OpenText, which uses FieldInfo, works OK. The second call, which passes
EmptyParam for the FieldInfo parameter, does not work -- returns OLE error
800A03EC. I don't know what this error means...

If I try to use Excel 2000's TLB, my project doesn't compile. As one might
expect, I get a "Not enough actual parameters" error on the OpenText call.

Any other thoughts?

Thanks,
Julian Slade

Re:Work with Excel 97 AND 2000??


<<Julian Slade:
If I try to use Excel 2000's TLB, my project doesn't compile. As
one might expect, I get a "Not enough actual parameters" error
on the OpenText call.

Quote

Use the Excel 2000 TLB. If you don't need to specify the extra
parameters, you can use the _OpenText method (NB added
underscore) which has the same parameters as the 97 version.
--
Deborah Pate (no emails please!)

Re:Work with Excel 97 AND 2000??


Deborah,

Thanks for the answer, but...
If I use the _OpenText method -- which is defined in Excel 2000 TLB, but not
in Excel 97 TLB -- how can that possibly work with Excel 97?

Thanks,

Julian Slade

Quote
"Deborah Pate" <d.p...@cableinet.co.not-this-bit.uk> wrote in message

news:38ff0961@dnews...
Quote
> <<Julian Slade:
> If I try to use Excel 2000's TLB, my project doesn't compile. As
> one might expect, I get a "Not enough actual parameters" error
> on the OpenText call.

> Use the Excel 2000 TLB. If you don't need to specify the extra
> parameters, you can use the _OpenText method (NB added
> underscore) which has the same parameters as the 97 version.

> --
> Deborah Pate (no emails please!)

Re:Work with Excel 97 AND 2000??


<<Julian Slade:
If I use the _OpenText method -- which is defined in Excel
2000 TLB, but not in Excel 97 TLB -- how can that possibly
work with Excel 97?

Quote

Because it is provided for that very purpose? Word2000 has
PrintOld, AddOld, OpenOld methods for the same reason.
Don't forget that the name in the type library means nothing
when you're using interfaces (which is why methods which
have inconvenient names, such as Goto, can have an
underscore added to them to prevent clashes with reserved
words). Only vtables and dispids matter.

--
Deborah Pate (no emails please!)

Re:Work with Excel 97 AND 2000??


Deborah,

Thanks for explaining. I guess there's a bit of a mental shift required
here.

I'll try your suggestion on Monday.

Thanks,

Julian Slade

Quote
"Deborah Pate" <d.p...@cableinet.co.not-this-bit.uk> wrote in message

news:38ff8aeb@dnews...
Quote
> <<Julian Slade:
> If I use the _OpenText method -- which is defined in Excel
> 2000 TLB, but not in Excel 97 TLB -- how can that possibly
> work with Excel 97?

> Because it is provided for that very purpose? ...
> Don't forget that the name in the type library means nothing
> when you're using interfaces (which is why methods which
> have inconvenient names, such as Goto, can have an
> underscore added to them to prevent clashes with reserved
> words). Only vtables and dispids matter.

Re:Work with Excel 97 AND 2000??


Well, I tried using _OpenText (from Excel 2000 TLB) and I'm still having
problems running with Excel 2000. (It works OK with Excel 97.) I guess it
must be something else I'm doing wrong.
The code I wrote last week using LATE binding works fine, so I'll just go
with that.

Thanks for your assistance.

Julian Slade

Other Threads