Writing a DLL for Excel in Delphi

I am using Turbo Delphi 2006.

The DLL will be called from Excel as part of the VBA / DLL combination.

The first part of the problem is trying to figure out how to pass the DLL a reference to the current Excel session. The most different code I have seen is that it started a separate instance of Excel besides the one you are in.

I've seen some C ++ code that instantiates IDispatch

and then passes something to a method of an IDispatch object, but I don't know much C ++.

Any ideas?

0


source to share


3 answers


What you are describing is called writing a COM add-on. You need to create an automation DLL and implement the interface IDTExtensibility2

. After that, you will receive the Excel interface Application

as a parameter of the method OnConnection

.

You will also need to register your DLL as an add-on for Excel to load it automatically.



EDIT: Forgot to mention: you can take a look at Add-in Express . Their structure and components make getting started with making Office addons ridiculously easy. You definitely don't have to worry about the details IDTExtensibility2

. However, anything related to the (reasonable) price,

+7


source


Delphi comes with a set of ActiveX controls to provide full access to Excel and other Office applications. They should be on the Servers tab of the tool palette.

If they are missing, select Components | Install Packages and scroll down to the very bottom and select the correct package.

In a default installation, they should be called:

Microsoft Office Automation Server Wrapper Components



and there should be one for XP and Win2k. XP will run on Vista.

Now if you want to automate Excel.

If you just want to add functionality to Excel using Delphi, I would suggest using a COM object, as I suspect Excel is very accepting of COM objects. Otherwise, you can create a direct DLL and use it just like Excel uses any other DLL.

+3


source


I don't know much about Office, but I think you should be using COM / ActiveX. Then you will get your IDispatch as well. See http://delphi.about.com/od/comoleactivex/OLE_COM_DCOM_Automation_ActiveX_Delphi_knowledge_base.htm

0


source







All Articles