Click to See Complete Forum and Search --> : Automation of Excel using .dlls in C++ .net


YoelPlat
May 25th, 2006, 06:05 PM
I'm trying to have VBA code in Excel call a method inside a dll of mine. I want the method to be able to modify the excel spreadsheet. I use GetActiveObject() to get the current Excel Application. I know that I'm definetly getting the object since I can change it's visibility property. However, when I try to do things like Add a workbook nothing happens, and when I try to modify a cell, I get an exception inside excel. My code works without a .dll - that is I can use a Windows Form Application to GetActiveObject(), modify it however I like, even save it and close it. Any ideas on how to change my .dll? This is what my .h file looks like:

#pragma once

#define DllExport __declspec( dllexport )

using namespace System;

using namespace Microsoft::Office::Interop::Excel;

#define Excel Microsoft::Office::Interop::Excel

namespace AddNumsCL {

public class Class1

{

public:

static DllExport int __stdcall myAdd(int a, int b, char * name);


};

}



Addtionally, if I add the 'ref' key word and get rid of "DllExport" and "__stdcall" then the excel doesn't call the method, even though I use the correct Alias from the .map file.

Thanks,

Yoel