Results 1 to 14 of 14

Thread: opening word doc

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    opening word doc

    I am trying to open up a word document... and i keep getting an error,

    here is my code

    Dim oWord As Object

    oWord = CreateObject("Word.Application")
    oWord.Visible = True
    oWord.Document.Open(Application.StartupPath & "\QuickStartManual.doc")


    Thanks!

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: opening word doc

    Tryb this:

    VB Code:
    1. Dim wdWord As Object
    2. Dim wdDocument As Object
    3. Set wdWord = CreateObject("Word.Application")
    4. Set wdDocument = CreateObject("Word.Document")
    5. Set wdDocument = wdWord.Documents.Open(wdWord.StartupPath & "\QuickStartManual.doc")
    6. wdWord.Visible = True

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  3. #3
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: opening word doc

    Hi,

    It's "Set oword = Createobject..."

    zaza

    EDIT: Rats. Beaten to it.

  4. #4
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: opening word doc

    Quote Originally Posted by zaza
    Hi,

    It's "Set oword = Createobject..."

    zaza

    EDIT: Rats. Beaten to it.

    Sorry about that... It happens all the time to everyone (Me too )

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Re: opening word doc

    whenever i type "Set" it disapears. i am still getting an error. any suggestions?

  6. #6
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: opening word doc

    Quote Originally Posted by xxwhocaresxx
    whenever i type "Set" it disapears. i am still getting an error. any suggestions?
    What error are you getting?

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Re: opening word doc

    it breaks my code and it says:

    "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occured in microsoft.visualbasic.dll"

    i don't know if that helps any.

  8. #8
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: opening word doc

    Quote Originally Posted by xxwhocaresxx
    it breaks my code and it says:

    "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occured in microsoft.visualbasic.dll"

    i don't know if that helps any.
    I do not think that is to do with the VB code I gave you.

    Are you using VB or VB.net?

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    13

    Re: opening word doc

    i don't think its the code either, but i am not sure what might be causing that error.

    i am using vb.net and word 2003

  10. #10
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: opening word doc

    Quote Originally Posted by xxwhocaresxx
    i don't think its the code either, but i am not sure what might be causing that error.

    i am using vb.net and word 2003
    Ah, thought I had never seen that error in VB before.

    You will havw to wait for the RobDog888 to have a look at this thread, I believe he knows VB.net and so should be able to help you

    Cheers,

    RyanJ
    My Blog.

    Ryan Jones.

  11. #11
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: opening word doc

    Hi,

    Where does it give you that error? I thought VBA was VB6...unless it is because you're importing a control or library or something you've created in .Net. I suspect that this is more to do with that than to do with your VBA code.



    zaza

  12. #12
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: opening word doc

    xxwhocaresxx i don't think its the code either, but i am not sure what might be causing that error.

    i am using vb.net and word 2003
    Perhaps a help file search for creating objects in .Net or maybe 'automation' ?

    Edit:
    Possibly helpful links?
    MSDN site
    Last edited by Ecniv; Jun 3rd, 2005 at 03:07 AM.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  13. #13
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: opening word doc

    Listen up ppl. Firstly, don't post VB.Net questions in a VBA forum because it does my head in.

    Set is no longer needed in .Net and the compiler ignores it and deletes it as soon as you try to use it.

    xxwhocaresxx: have you added a reference to the relevant Word object library? You'll need to do that in order to create an instance of the word application.

    For my outlook program i just used a reference to Interop.Office.dll and then this code to create an outlook app object...

    VB Code:
    1. Private OutApp As Outlook.ApplicationClass
    2. ............
    3. OutApp = New Outlook.ApplicationClass

    You should be able to figure out how to do the equivalent Word version for yourself.
    I don't live here any more.

  14. #14
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: opening word doc

    To clarify the difference between the languages:

    VBA = The village idiot. This guy is very slow witted and finds it hard to understand simple things.

    VB6 = The family man, has 2.4 children and a labrador. Knows what he wants to do and does it his own way with little time for the new fangled methods. Reliable, gets the job done.

    VB.Net = Extreme sports fanatic, control freak, slightly intense, irritable.
    I don't live here any more.

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