We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

The following tip can be used to avoid any problem in opening a word document in multiple versions of MS Word in different systems.
 
If we have a reference to Microsoft Word 8.0 Object Library and wrote the following code in VB.Net to open a word document.
 
 
Dim oWord As Word.ApplicationClass
 
oWard = CreateObject("Word.Application")
oWord.Visible = True
oWord.documents.Open(Application.StartupPath & "\File1.doc")
 
 
This method is called the Early binding way to programmatically control another application.
 
But above code may result in popping up an error message such as :
 
QueryInterface for interface for word._Application failed
at Word.ApplicationClass.set_Visible(Boolean prop)
Solution :
 
Late binding is the only way to work with multiple versions of MS Word.Therefore don't use a reference at design time, late binding will grab the reference at run time.
 
Late binding uses CreateObject to create an instance of Application object, which you can then control.
 
Code Example:
 
Dim oWord As New Object
 
oWord = CreateObject("Word.Application")
oWord.Visible = True
oWord.Documents.Open(Application.StartupPath & "\File1.doc")
 
 
The only difference is the "Dim oWord As New Object" bit because we are just telling .Net that it is going to be a reference to something there, and then we define the reference by using the CreateObject command.
 
Read More on this:
http://support.microsoft.com/kb/245115 


Related Tags:

VB.NET

Author: Shibani Subhadarshini

top

VB.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login