Solved

Accessing VB.NET class from Word 2007 VBA

Posted on 2009-07-16
7
503 Views
Last Modified: 2013-11-10
I have a VB.NET (VS2008) application that, in part, performs some automation in a Word 2007 document.  However the VB.NET application does not recieve events from the Word application, so I have written some code in a template within Word to respond to events.  The problem is that I now need to access some classes in my VB.NET application from the Word VBA, or else duplicate all that code within the Word template.

Thanks very much.
0
Comment
Question by:AbeFisher
  • 4
  • 3
7 Comments
 
LVL 8

Expert Comment

by:rseabird
ID: 24872330
Hi, why not using VSTO for Visual Studio 2008? You can easily create you Word Add-on (or whatever you like) with full ability to the functions of Word.
0
 

Author Comment

by:AbeFisher
ID: 24873606
I'm sorry - I don't quite understand your suggestion.  What do you mean by "using VSTO for Visual Studio 2008"?
Perhaps some additional clarification is in order.  I have written an app in VB.NET that runs independently and has several functions.  Only one of these functions is to insert formatted text into MS Word.  So I don't want to migrate the whole project to VBA; rather I am just trying to accomplish some specific communication between the code written in Word VBA/VSTO and the code written in Visual Studio:  either raise events in the Word VBA code that can be handled by the VB code, or allow the VBA code to access classes in the VB project.
Does that help?
0
 
LVL 8

Expert Comment

by:rseabird
ID: 24876284
VSTO = Visual Studio Tools for Office.
With these tools you can easily create Office Add-in solutions in .NET. In your situation I suggest to create an Word Add-in with VSTO, create a reference to your other .NET app, and you can just use the advantage of Word functionality as well as your own .NET app. No need to migrate code to VBa.
By the way, VSTO is free to download at Microsoft.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:AbeFisher
ID: 24878980
Thank you rseabird.
My question, however, is HOW to do the very thing you suggest.  I believe with VS 2008 VSTO are included and already installed - at least I am able to create a Word Add-In project in VB.NET.  Within this project I can see the application level events, but not the document level events.  So my question is twofold, I guess:
1.  How do I get the document level events to show up?
2. How do I go about creating a reference to my other .NET app?  Is that some sort of "include" statement?  What is the syntax?
Thanks very much!
0
 
LVL 8

Accepted Solution

by:
rseabird earned 250 total points
ID: 24886744
Just a brief answer for this moment,
You have your application object, inside you can find your current document. I am not complete sure, but I thought there you can find events etc.
About creating a reference, that's the normal way you do it in any ordinary VS2008 solution. Add a reference in your project properties and use the imports statement at the top of the class where you want to use it.
0
 

Author Comment

by:AbeFisher
ID: 24891944
Thanks for giving this a shot.  I finally got it to work --
In the VB.NET Add-in application, I created a document class and instantiated it WithEvents, then was able to access the document level events.  As for accessing the class that is part of my original VB.NEt application, I just loaded that class module into the Add-In application.  This works, but is not ideal, as I now need to maintain it in two locations.  Eventually I'll try to make this class stand-alone, and compile it, so I can import it into each project as a .dll.
0
 

Author Closing Comment

by:AbeFisher
ID: 31604286
This started me in the right direction, but lacked the specifics necessary to understand what I really needed to do.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question