Word VBA Problem

Madpony

New member
Joined
Oct 20, 2003
Messages
3
Location
Bloomington, IL
I recently wrote a small VB .NET application that generates Mailing Labels in Microsoft Word. When I tested the program on a computer with Windows XP Pro and Office XP it ran perfectly fine. The program also runs great on a Windows 2000 computer that also has Office XP.

However, when I installed it on a machine with Windows 2000 and Office 2000, it gives me the following error even with the Microsoft .NET framework installed.

Does anyone have any ideas on how to resolve this error? Any advise is highly appreciated!

Heres the error message:



See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at Word.MailingLabel.CreateNewDocument(Object& Name, Object& Address, Object& AutoText, Object& ExtractAddress, Object& LaserTray, Object& PrintEPostageLabel, Object& Vertical)
at Label_Generator.LabelGenForm.btnGenerate_Click(Object sender, EventArgs e) in C:\Documents and Settings\MikeB\My Documents\Visual Studio Projects\Label Generator\LabelGen.vb:line 240
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
Label Generator
Assembly Version: 1.0.1382.16528
Win32 Version: 1.0.1382.16528
CodeBase: file:///C:/Program%20Files/Label%20Generator/Label%20Generator.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.3052.4
CodeBase: file:///c:/winnt/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
Interop.Word
Assembly Version: 8.2.0.0
Win32 Version: 8.2.0.0
CodeBase: file:///C:/Program%20Files/Label%20Generator/Interop.Word.DLL
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.
 
what is line 240 in your code? (You can turn line numbering on via options). On that particular line is the object/function an Office XP only object/function. My guess would be that since this works fine regardless of the machine as long as its Office XP that the problem is caused because somewhere in your code your mentioning something that Office 2000 doesnt understand (such as a new function/object that came out with Office XP). Write your code to work on Office 2000 then it will almost certainly work on XP because XP is newer and therefore will more than likely have backwards compatibility built in.
 
Thanks for replying to my message!

It actually ended up being a problem of early vs. late binding. I was doing early binding on the Word Application object where late binding was required.

After changing the object binding type, everything worked fine!
 
The binding made a differance between office versions? Interesting..... glad to hear you got it though... early/late binding snagged me a few times in the past too.
 
Back
Top