PDA

Click to See Complete Forum and Search --> : Opening a Word 2000 document in VB.Net


RSX
Mar 3rd, 2003, 02:43 PM
I'm pretty new to VB.Net so take it easy on me :D
I'm on Win2K with Office 2000 and all I'm trying to do is open a work document. I've added a reference to Office 9.0 and Word 9.0 and this is the code I have.

Dim wordApp As Word.Application

wordApp = new Word.ApplicationClass
For some reason I can't use Word.Application in the above statement.

I've also tried this:
Dim wordApp as Word.Application
wordApp = CreateObject("Word.Application")

In both cases I get exceptions thrown :( Here are the messages I get:

Top Example:
An unhandled exception of type 'System.IO.FileNotFoundException'

Additional information: The specified module could not be found.

Bottom Example:
An unhandled exception of type 'System.Exception' occurred in microsoft.visualbasic.dll

Additional information: Cannot create ActiveX component.


Please help :confused:

MrGTI
Mar 3rd, 2003, 03:37 PM
I've done it like this:
Dim objWord As Object 'Declare an object variable
objWord = CreateObject("Word.Basic") 'Set the object pointer
With objWord
.FileNew() 'Create a new File in Word
.Bold() 'Make the Font Bold
.FontSize(24) 'Make the Font 24 point in size
.CenterPara() 'Center Text on page
.Insert("I entered in these words") 'Insert some text
.appShow() 'Shows us the doc in Word
'.FilePrintDefault 'Print the current document
'.FileClose 2 'Close file without saving.
End With
'Unloads Word from VB memory (awaits Garbage Collection)
objWord = Nothing
The code you are suggesting only works if you have OfficeXP installed (i think).

chinhow
Mar 6th, 2003, 11:21 PM
How to open an Microsoft Access Report in VB.Net?

Static
Mar 7th, 2003, 12:23 AM
Add a reference to Microsoft Word 9.0

Dim wrd As New Word.Application
wrd.Visible = True
wrd.Documents.Open("C:\Path\file.doc")


You need the NEW keyword...

(im on XP / Office 2000 so it whould work for you...)