473,657 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best Practise Advice Calling C# DLL from VBA

Can anybody give me a quick heads up on the best way to develop C# based
DLL's that are called via VBA.

I'm developing a pop-up window that will record information within SQL. I
need to launch this pop-up from an application that only supports VBA. So I
decided the best solution would be to create a DLL with C# that exposes the
methods needed to launch my pop-up window.

My first attempt didn't work and after spending several hours on the various
forums I now have a working solution, but still a little confused about best
practice.

The reason why it didn't work originally was because I forgot to click the
"Register for COM Interop". But other solutions talk about the GAC and
various un-friendly command line switches.

Once this "COM Interop" switch was checked I could see the DLL from Excel
VBA (used for testing solution) without doing anything else, however no
methods are exposed via intelesence... but it does work.

What is the best way to develop a small project using C# that can be called
via any VBA enabled application? I think the DLL approach is best but unsure
of what has to be done in the C# environment to get this to work the same
way VB6 based DLL's used to.

Any assistance gratefully received.

Steve Le Monnier
Sep 18 '06 #1
2 2370
Hi Steve,

Note that this isn't anything I've really tried, but I do read articles and
threads that discuss it and...

I think you also have to create and expose an INTERFACE with the methods you
want to call through COM. I'm looking at Andrew Whitechapel's ".NET development
for Microsoft Office", where there's a detailed list of steps. The bit of
sample code for the Interface looks like this
[GUID("number-thingy-here")]
[ComVisible(true )]
public interface IExtraStuff //same name as class library project
{
double F2C(double val); //the method to be exposed
}

the it says to implement the interface in a public class, also GUID attributed
AND attributed with ClassInterface( ClassInterfaceT ype.None). Put the methods in
this public class.
Can anybody give me a quick heads up on the best way to develop C# based
DLL's that are called via VBA.

I'm developing a pop-up window that will record information within SQL. I
need to launch this pop-up from an application that only supports VBA. So I
decided the best solution would be to create a DLL with C# that exposes the
methods needed to launch my pop-up window.

My first attempt didn't work and after spending several hours on the various
forums I now have a working solution, but still a little confused about best
practice.

The reason why it didn't work originally was because I forgot to click the
"Register for COM Interop". But other solutions talk about the GAC and
various un-friendly command line switches.

Once this "COM Interop" switch was checked I could see the DLL from Excel
VBA (used for testing solution) without doing anything else, however no
methods are exposed via intelesence... but it does work.

What is the best way to develop a small project using C# that can be called
via any VBA enabled application? I think the DLL approach is best but unsure
of what has to be done in the C# environment to get this to work the same
way VB6 based DLL's used to.
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :-)

Sep 19 '06 #2
Many thanks Cindy, will check out that article and do a little more R&D.

Cheers
"Cindy M." <C.*********@hi speed.chwrote in message
news:VA.000003b 3.0096bd0c@spee dy...
Hi Steve,

Note that this isn't anything I've really tried, but I do read articles
and
threads that discuss it and...

I think you also have to create and expose an INTERFACE with the methods
you
want to call through COM. I'm looking at Andrew Whitechapel's ".NET
development
for Microsoft Office", where there's a detailed list of steps. The bit of
sample code for the Interface looks like this
[GUID("number-thingy-here")]
[ComVisible(true )]
public interface IExtraStuff //same name as class library project
{
double F2C(double val); //the method to be exposed
}

the it says to implement the interface in a public class, also GUID
attributed
AND attributed with ClassInterface( ClassInterfaceT ype.None). Put the
methods in
this public class.
>Can anybody give me a quick heads up on the best way to develop C# based
DLL's that are called via VBA.

I'm developing a pop-up window that will record information within SQL. I
need to launch this pop-up from an application that only supports VBA. So
I
decided the best solution would be to create a DLL with C# that exposes
the
methods needed to launch my pop-up window.

My first attempt didn't work and after spending several hours on the
various
forums I now have a working solution, but still a little confused about
best
practice.

The reason why it didn't work originally was because I forgot to click
the
"Register for COM Interop". But other solutions talk about the GAC and
various un-friendly command line switches.

Once this "COM Interop" switch was checked I could see the DLL from Excel
VBA (used for testing solution) without doing anything else, however no
methods are exposed via intelesence... but it does work.

What is the best way to develop a small project using C# that can be
called
via any VBA enabled application? I think the DLL approach is best but
unsure
of what has to be done in the C# environment to get this to work the same
way VB6 based DLL's used to.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply
in the newsgroup and not by e-mail :-)

Sep 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1790
by: Phlip | last post by:
Newsgroupies: Good guidelines keep source code within a "comfort zone". Programming languages provide extraordinarily wide design spaces, much wider than hardware designs enjoy, with many tricks and backdoors that could provide hours of pleasant diversion writing obfuscated code. Don't write like that on the job. Always write similar, obvious statements to do similar, simple things. Engineers learn their working vocabulary from...
1
1911
by: sufferthefools | last post by:
i have been taught always to use the data module and place all the necesary components on it and refer to it when i need something. but is this the best programming practise?? i get a lot of access violation messages and now that i want to make the entire program dll based (so it can be easier to update) i sit with a problem. how to use that data module. do i include it to every dll project or do make it a dll and then reference it??
2
10100
by: bonk | last post by:
I have come across the need to distinguish between the creation of a deep and a shallow copy and with great interest I have read this article: http://blogs.msdn.com/brada/archive/2004/05/03/125427.aspx This artivle seems to hint that I should not use System.IClonable but instead define my own interface(s) for cloning. Now since this article is rather old and since they did not obsolete IClonable there might be a new "best practise".
5
1626
by: Rich | last post by:
Hi, I would welcome any opinions on the best approach to developing a web app in order to meet the following requirements: a) the user interface can be easily styled by a graphic designer. b) the content pages can be embedded in other apps if needed (E.g. Outlook). My personal view (being heavily biased to ASP.Net) is to make full use
4
1834
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is logged in, on each and every page, and redirects the user to a login page if s/he's not logged in. The login page will also take care of some standard setup, such as choosing/populating a user profile. I used to use <!-- #include ... --for this,...
16
2794
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
9
7877
by: Paul | last post by:
Hi, I feel I'm going around circles on this one and would appreciate some other points of view. From a design / encapsulation point of view, what's the best practise for returning a private List<as a property. Consider the example below, the class "ListTest" contains a private "List<>" called "strings" - it also provides a public method to add to that list,
41
2861
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be created and then added to "component" objects to build up the component definition. My dilemma comes in deciding how to read/write data to the "item"
41
1872
by: =?Utf-8?B?VGltIE1hcnNkZW4=?= | last post by:
Hi, I am after suggestions on the best practice declaring and destroying objects. some example code: Private Sub MySub Dim frmMyForm As MyForm Try
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8740
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.