Microsoft Word Object Library in VB.NET - Office 2007, Word 2007, Old OLB Versions

I am writing a program in Visual Studio 2005 (VB.NET), which will need to open a Word Document and insert data into it from a database.

I have done this with VB6 and Office 2000 with no problem. Problem here is that I have Office 2007 Installed, but I need my compiled VB.NET program to work on machines with lower versions of Office (2000 and up, or even 2003 and up). I don't think I can use the Office 12 Object Library because it's for Office 2007 and won't work with 2000. I am under the impression that if I use an old version of the OLB, it will be "forward compatible" and work with all later versions. Is this true?

If I do need older versions of the OLB, is there anywhere I can download a developer's distributable version so I can reference it in my program? Is there some other way to make this program "Backward compatible"?

Thanks in advance for any help!
LVL 3
paix120Asked:
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.

gbahriCommented:
I would suggest you to go for a late binding. Please refer these sites:

http://msdn2.microsoft.com/en-us/library/aa188643(office.10).aspx

http://word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Hope, this helps you a bit,

thanks,

GBahri
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
paix120Author Commented:
OK, thanks for the response. I'll check those sites out.
0
paix120Author Commented:
Well, I tried using:

Dim objWordApp As Object
Set objWordApp = createobject("Word.Application")

but it underlines "Set" and says there is a syntax error. Any ideas how to use this method properly in Visual Studio 2005, or why I'm getting the error?

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

paix120Author Commented:
I found the following in an article here: http://www.excelguru.ca/blog/category/visual-studio/
but I still can't get the syntax error-free
------------------------------------------------------------
Visual Basic:
oWord = CreateObject("Word.Application")

This does not work in VB.Net though, as "Option Strict On disallows implicit conversions from 'Object' to 'Microsoft.Office.Interop.Word.Application'."

Instead, we need to use the following to explicitly cast the Type:

Visual Basic:
'At the top of the module:

Imports Word = Microsoft.Office.Interop.Word

'In your procedure

oWord = CType(CreateObject("Word.Application"), Word.Application)
0
paix120Author Commented:
OK, duh. The "set" wasn't working because it was outside of a subprocedure.

This is what I have now:
(outside sub)
Dim objWordApp As Object
Dim objWordDoc As Object

(in constructor)
   objWordApp = CType(CreateObject("Word.Application"), Microsoft.Office.Interop.Word.Application)
   objWordDoc = CType(CreateObject("Word.Document"), Microsoft.Office.Interop.Word.Document)

I now understand the big downside to doing it this way - When I do objWordDoc.
no methods or procedures come up. I guess that's the point of late binding.

Next step for me is to test this on an older version of Word and see what happens. I just did a find/replace, so it's still using commands from the Office 2007 OLB I was using.

OK it's really late. I'll get on this again tomorrow.
0
GrahamSkanRetiredCommented:
'Set' is not used in VB.Net.

You could try simply

objWordApp = createobject("Word.Application")

0
paix120Author Commented:
Yep, I figured that out when I found this solution:
objWordApp = CType(CreateObject("Word.Application"), Microsoft.Office.Interop.Word.Application)

Now, I am trying to figure out how to do all of the commands to output the document on an Office 2003 system without it crashing. When I get to the point where I know this "late binding" solution is the right choice to solve my initial problem, I'll come back and assign points.

Suggestions still welcome! Thanks.
0
paix120Author Commented:
OK still not working. All I had in my program was the command to open the document and insert some text. I created a Setup project and made sure the MS Word DLLs were included. I installed it on my Office XP computer and got this error:

Unable to cast COM object of type System.___ComObject to interface type Microsoft.Office.Interop.Word.Application. This operation failed because the Queryinterface call on the COM component for the interface …. Failed due to the following error: Error loading type library/DLL

So, apparently I still don't understand late binding enough to implement it. Any other links with help? I'm having a hard time finding anything online that I can understand.

Problem still not solved.
0
gbahriCommented:
Try using the System.Activator class to instantiate

see the following link with heading 'Using the Activator class to create singletons' for more information:

http://edndoc.esri.com/arcobjects/9.1/default.asp?url=/arcobjects/9.1/ArcGISDevHelp/DevelopmentEnvs/DotNet/SystemComObject.htm

thanks,

GBahri
0
paix120Author Commented:
OK - never heard of that - I will check that out soon. Thanks.
0
paix120Author Commented:
I looked at the code, but I don't really understand what it's doing... can you explain the concept a bit? Thanks!
0
paix120Author Commented:
YAY! I figured out the problem, and it turns out something was wrong with my Word installation. I tried to open the VBA macro editor from inside Word on my computer with Office XP and it said
Said "This application is not working properly", so I clicked "Repair" and it asked for Office XP CD. I put it in and then it said "Installing Word Feature" and opened the VB Editor successfully.

So, from advice given on this thread and on my other open question:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_22497155.html

I at least have it successfully opening and writing to a Word Doc now, and since I'm developing on a computer with Office XP, it should be compatible with later versions of Word. Thanks for the help!

I don't know if my problem is completely solved, but I'm so glad it's even working at all at this point, I'm going to assign points and I'll ask a new question if I come across any other problems.


0
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
.NET Programming

From novice to tech pro — start learning today.