Solved

Accessing VB.NET class from Word 2007 VBA

Posted on 2009-07-16
7
506 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
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…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

679 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