Results 1 to 13 of 13

Thread: how to create an instance of ms word using vb?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74

    Unhappy how to create an instance of ms word using vb?

    people,

    how do you open a ms word document in vb? i kept receiving this error:

    "Activex component can't create object"

    thanks!

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    VB Code:
    1. Option Explicit
    2.  
    3. Private objWord As Word.Application
    4. Private wd As Word.Document
    5.  
    6. Private Sub Command1_Click()
    7.     Dim myRange As Range
    8.     Dim sSearchfor As String
    9.  
    10.     If objWord Is Nothing Then
    11.         Set objWord = CreateObject("Word.Application")
    12.     Else
    13.         Set objWord = GetObject(, "Word.Application")
    14.     End If
    15.     DoEvents
    16.     Set wd = objWord.Documents.Open("c:\Test.doc")
    17.     'here u can do stuff with the document
    18.     'using the wd object
    19.    
    20.     'when finished manipulating the document, u can show _
    21.     it To the user
    22.     objWord.Visible = True
    23. End Sub
    -= a peet post =-

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74

    same error

    Option Explicit

    Private objWord As Word.Application
    Private wd As Word.Document

    Private Sub Command1_Click()
    Dim myRange As Range
    Dim sSearchfor As String

    If objWord Is Nothing Then
    Set objWord = CreateObject("Word.Application")
    Else
    Set objWord = GetObject(, "Word.Application")
    End If
    DoEvents
    Set wd = objWord.Documents.Open("c:\Test.doc")
    'here u can do stuff with the document
    'using the wd object

    'when finished manipulating the document, u can show _
    it To the user
    objWord.Visible = True
    End Sub


    still got the same error message.
    does it have something to do with dll's or license etc.?

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Have u referenced the Microsoft Word Object?
    -= a peet post =-

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74
    yes.

    microsoft word 9.0 object library.

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    At what line in the code does the error occur?
    -= a peet post =-

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74
    the CreateObject line.

    before, i used

    dim appword as word.application
    Set appword = NEW word.application

    but i received the same error. my guess is that because of the its of the NEW command. it worked when i first opened the MS word application manually then referenced the appword object to the word.application (Set appword = word.application)

  8. #8
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Err...if all you want to do is open a word instance...this works for me (after word references are added):

    VB Code:
    1. Dim WordApp As New Word.Application
    2. WordApp.Visible = True

    And if you want to add a blank doc, do
    VB Code:
    1. WordApp.Documents.Add

    Although i might have missed something since Peet has way more code than that.
    You just proved that sig advertisements work.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74
    still the same error
    maybe this could help.

    The computer on which you are running the code has a run-time license rather than a design-time license for this control.


    With a run-time license, you can load the control but you cannot create or insert it. The design-time license for this control ships with the Microsoft Office 2000 Developer Edition or Microsoft Visual Studio. It does not ship with other versions of Microsoft Office 2000.

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74

    help!!!

    anyone? please...

  11. #11
    Frenzied Member nishantp's Avatar
    Join Date
    Jan 2001
    Location
    Where you least expect me to be
    Posts
    1,375
    Lol well if you know that you dont have the license..then working around it is probably illegal....but like thats ever stopped anyone
    You just proved that sig advertisements work.

  12. #12
    Member
    Join Date
    Oct 2000
    Location
    Philadelphia
    Posts
    47

    had this problem

    I actually had this problem for awhile, working with windows 2000 and office 2000. The solution to your problem is installing an older version of the office update. If you install the lates office update (2) then this will solve the problem, it is also recommended that you install any updates to windows 2000. Your code is right, if you compile and run on another machine it will work. Good Luck
    U S A
    Visual Studio .NET
    Windows XP

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Sep 2001
    Location
    manila, philippines
    Posts
    74
    thank you very much for your reply!!!


    what again should i do?

    should i install the older office update or the lates office update?


    thanks again !!!

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