Jump to content
ByteJuggler

Importing Excel2016 Type library into Delphi

Recommended Posts

Hi all,

 

I'm trying to import the Excel 2016 type library into Delphi in the normal way via "Component"->"Import Component"->"Import ActiveX Control", click "Add", browse to "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" (list changes and has only the selected type lib loaded), "Next>>", filling in the fields as desired, and then clicking "Next >>", Selecting "Create Unit" and clicking "Finish" which then generates the below error ("Error loading type library Excel (Version 1.9).")

 

https://i.vgy.me/DvFI6h.png

 

I've also gone to the trouble of extracting the actual Type Library resource from Excel.exe using Visual Studio and importing that directly instead.  (In the above process you select "Import a type library" instead of "Import ActiveX Control".)  The result is essentially the same, e.g. the same error is generated.

 

I should note that this is the 64-bit version of Office that is installed, and I'm aware that I've tried to directly import the server/tlb interfaces directly from the 64-bit Excel executable and that this might be part of the problem.  I'm unsure whether this is legitimate or whether that's part of the problem, but if this is a problem I'm not sure what I should be importing instead? (Is there some kind of 32-bit wrapper library that I should be importing instead? If so what?)

 

Thanks!

Edited by ByteJuggler

Share this post


Link to post

If you execute the import component dialog and select "import type library" you should get a list of the installed type libraries on the next page of the wizard. Don't you see a "Microsoft Excel xx.x Object Library" in that list?

Share this post


Link to post

No it doesn't appear in that list.  And I've by now managed to solve the whole problem, thanks! 🙂  (As far as I can tell 🙂 Oh, and sans designtime component icons but that's hardly important.)

 

I (vaguely) remembered that the Delphi IDE only lists the servers/type libraries/components listed in the 32bit registry, and then managed to (re)locate this page, which states this and mentions that despite the IDE choking on 64-bit imports (as I've found), the TLIBIMP.EXE command line tool works fine.  I hence successfully used it to import the Excel 2016 library and built and installed them into the IDE.  For reference the command used to import the type library was:

 

"C:\Program Files (x86)\Embarcadero\Studio\18.0\bin64\tlibimp.exe" -P "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"

 

There's some fiddling required with the output files to make them match Embarcadero's conventions on their own imports (e.g. change from *_TLB.pas to *2016.pas in this instance).  You also  obviously need to create a Delphi component project to contain the wrapper components, which should be named dclOffice2016.dproj assuming you want to again match Emba's conventions.  Inside the project options you should then also set the library suffix to match the product version that you're using and probably set a suitable description.  (In my case Delphi Berlin which is product version 24 and suffix 240 as shown here.)

Edited by ByteJuggler

Share this post


Link to post

@ByteJuggler Out of interest (as I do COM DLLs for Excel 32 and 64) I assume you are having to import the 64-bit version as you do not have 32-bit and you want to use feature post Office 2002?

 

Share this post


Link to post
42 minutes ago, David Hoyle said:

@ByteJuggler Out of interest (as I do COM DLLs for Excel 32 and 64) I assume you are having to import the 64-bit version as you do not have 32-bit and you want to use feature post Office 2002?

 

Correct.  

Share this post


Link to post

In case anyone else runs across this thread in the future and are stuck trying to import the type library for MS Word (WinWord.exe), note that unlike with Excel where the type library can be imported from the .EXE file, with WinWord the Type Library is not embedded (it seems) in the .EXE file, so you run into an error if you try the same approach as above.  

 

It turns out that for many Office applications the type library information is stored in .OLB files.  For more on this see: https://docs.microsoft.com/en-us/office/troubleshoot/office-developer/use-type-library-for-office-from-visual-c-net

 

The full command i used to import the type libraries related to MS Word (WinWord) was:

"C:\Program Files (x86)\Embarcadero\Studio\18.0\bin64\tlibimp.exe" -P "C:\Program Files\Microsoft Office\root\Office16\MSWORD.OLB"

Adjust as required for the version of Delphi and/or Office you're using.  The files will be created in the current folder, so be sure to be in the target folder before you run the command.  The output is something like this:

C:\temp\import>"C:\Program Files (x86)\Embarcadero\Studio\18.0\bin64\tlibimp.exe" -P "C:\Program Files\Microsoft Office\root\Office16\MSWORD.OLB"
Embarcadero TLIBIMP Version 12.16581 [x64]
Copyright(c) 1995-2010 Embarcadero Technologies, Inc.

Opening  C:\Program Files\Microsoft Office\root\Office16\MSWORD.OLB
Type library loaded ....
Created  C:\temp\import\Office_TLB.dcr
Created  C:\temp\import\Office_TLB.pas
Created  C:\temp\import\VBIDE_TLB.dcr
Created  C:\temp\import\VBIDE_TLB.pas
Created  C:\temp\import\Word_TLB.dcr
Created  C:\temp\import\Word_TLB.pas

C:\temp\import>

Hope that helps future me or some other soul... 🙂

  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×