Results 1 to 4 of 4

Thread: Opening a Word 2000 document in VB.Net

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2003
    Posts
    1

    Post Opening a Word 2000 document in VB.Net

    I'm pretty new to VB.Net so take it easy on me
    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

  2. #2
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277
    I've done it like this:
    VB Code:
    1. Dim objWord As Object                   'Declare an object variable
    2.         objWord = CreateObject("Word.Basic")    'Set the object pointer
    3.         With objWord
    4.             .FileNew()                          'Create a new File in Word
    5.             .Bold()                             'Make the Font Bold
    6.             .FontSize(24)                       'Make the Font 24 point in size
    7.             .CenterPara()                       'Center Text on page
    8.             .Insert("I entered in these words") 'Insert some text
    9.             .appShow()                          'Shows us the doc in Word
    10.             '.FilePrintDefault                   'Print the current document
    11.             '.FileClose 2                        'Close file without saving.
    12.         End With
    13.         'Unloads Word from VB memory (awaits Garbage Collection)
    14.         objWord = Nothing
    The code you are suggesting only works if you have OfficeXP installed (i think).
    ~Peter


  3. #3
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Opening Access Report in vb.net

    How to open an Microsoft Access Report in VB.Net?

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    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...)
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width