Can code developed in C# .NET 3.5 be imported to VBA for Office 2008?

Hi All,

I was wondering, is it possible to create code in C# .NET 3.5 and build the dll's and somehow import the library in standard VBA macro in Word.

Can I then call the library and use its methods? Maybe using an Active X control?

Cheers
lp84Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JackOfPHCommented:
What version of word?
0
JackOfPHCommented:
Yes, it can be done:

create the dll build it then use tblexp.exe or use regasm.exe.

http://msdn.microsoft.com/en-us/library/hfzzah2c%28VS.80%29.aspx

Tlbexp.exe generates a type library that contains definitions of the types defined in the assembly. Applications such as Visual Basic 6.0 can use the generated type library to bind to the .NET types defined in the assembly.

The entire assembly is converted at once. You cannot use Tlbexp.exe to generate type information for a subset of the types defined in an assembly.

You cannot use Tlbexp.exe to produce a type library from an assembly that was imported using the Type Library Importer (Tlbimp.exe). Instead, you should refer to the original type library that was imported with Tlbimp.exe. You can export a type library from an assembly that references assemblies that were imported using Tlbimp.exe. See the examples section below.

Tlbexp.exe places generated type libraries in the current working directory or the directory specified for the output file. A single assembly might cause several type libraries to be generated.

Tlbexp.exe generates a type library but does not register it. This is in contrast to the Assembly Registration tool (Regasm.exe), which both generates and registers a type library. To generate and register a type library with COM, use Regasm.exe.

If you do not specify either the /win32 or /win64 option, Tlbexp.exe generates a 32-bit or 64-bit type library that corresponds to the type of computer on which you are performing the compilation (32-bit or 64-bit computer). For cross-compilation purposes, you can use the /win64 option on a 32-bit computer to generate a 64-bit type library and you can use the /win32 option on a 64-bit computer to generate a 32-bit type library. In 32-bit type libraries, the SYSKIND value is set to SYS_WIN32. In 64-bit type libraries, the SYSKIND value is set to SYS_WIN64. All data type transformations (for example, pointer-sized data types such as IntPtr and UIntPtr) are converted appropriately.
0
lp84Author Commented:
So are you saying regasm is better to use?

http://msdn.microsoft.com/en-us/library/tzat5yw6(VS.71).aspx
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

lp84Author Commented:
This is for MS Office 2007, Word 2007
0
JackOfPHCommented:
If this is for the MS Office 2007 then no need to use regasm, you can imports the dll directly to your macro...
0
Miguel OzSoftware EngineerCommented:
Check:
How to: Expose Code to VBA in a Visual C# Project
http://msdn.microsoft.com/en-us/library/bb608604.aspx
Calling Code in Document-Level Customizations from VBA
http://msdn.microsoft.com/en-us/library/bb386306.aspx
If you have access to online books I will recommend Andrew Whitechapel's ".NET development
for Microsoft Office", where there's a detailed list of steps on how to do this task (better explained than my first link anyway)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.