Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Open Word document using VB.NET
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB.NET 1.1
OS:
Windows XP SP2
Database:
MS SQL Server
Miscellaneous
Thread ID:
00990971
Message ID:
00991443
Views:
52
>Hi Rick,
>
>You have to set the Option Strict Off in VB.NET to get late binding. You can't tell from the code.

Sorry - I'm ignorant on VB.NET <g> so I may be off, but I *think* this is how this works:

I think with Option Strict off CreateObject() still does late binding, but the returned type is of type object, so you'd have to use Reflection to access any members. With Option Strict On you can just call the methods and the compiler will automatically do the Reflection calls.

As far as I know CREATEOBJECT() always uses Late Binding - what would hte compiler bind against to do early binding? Unless you have done a TLBIMP (or using the Office Integration Kit). In that case you wouldn't use CreateObject() but the wrapper type...

Let me know if this is wrong - it'd actually help to understand this, because there are a few things where this kind of interaction with COM objects would be much preferrable over TLBIMP or Reflection access.


+++ Rick ---



But isn't the problem that
>
>>Uh, isn't that what he's doing already? He's using generic Word.Application (rather than the version specific ProgId)...
>>
>>I think the problem is something different since the error doesn't appear to occur on instantiation but when the doc is opened...
>>
>>+++ Rick ---
>>
>>>Hi Allan,
>>>
>>>When you are working with different versions of Word or Excel, you will need to write your Word interfacing with VB.NET, using Option Strict Off or use Reflection in C# (or VB.NET). This allows for late binding so the compiler does not link to a specific version. Here is a MSDN article that explains this and provides examples:
>>>
>>>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/OffCSharp.asp
>>>
>>>
>>>>Hi Bonnie,
>>>>
>>>>You're right. I have OfficeXP, the client has Office 2000.
>>>>
>>>>>Your problem is probably different versions of Word on your client's box than what's on your dev box. Unfortunately, there are slight differences in how Word is opened in Word 2000 vs Word 2003. Which do you have and which does your client have?
>>>>>
>>>>>~~Bonnie
>>>>>
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>Just trying to open a Word Document using VB.NET.
>>>>>>
>>>>>>This code works on my dev box.
>>>>>>
>>>>>>
>>>>>>
>>>>>>Dim wrdDoc As Word.Document
>>>>>>Dim wrdApp As Word.Application
>>>>>>Dim strLargEnvTemplate as String = "C:\EnvTemplate.doc"
>>>>>>
>>>>>>wrdApp = CType(CreateObject("Word.Application"), Word.Application)
>>>>>>wrdApp.Visible = True
>>>>>>
>>>>>>wrdDoc = wrdApp.Documents.Open(strLargEnvTemplate)
>>>>>>
>>>>>>
>>>>>>
>>>>>>However, at the client site, an exception is created on
>>>>>>
>>>>>>
>>>>>>
>>>>>>wrdDoc = wrdApp.Documents.Open(strLargEnvTemplate)
>>>>>>
>>>>>>'The error message is "Object Reference not set to instance of an object"
>>>>>>
>>>>>>'Word is instantiated OK - but the document will not load...
>>>>>>
>>>>>>
>>>>>>Any idea why the code works on my dev box but generates an exception on the production PC's?
>>>>>>
>>>>>>Is there a better way to open a Word Document from VB.NET?
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform