Results 1 to 8 of 8
  1. #1
    Lounger
    Join Date
    Feb 2001
    Location
    Upstate, New York, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Open Word doc from vba (Excel 2000/SR2)

    I have the following code behind a button on a user form to open a document in Word:

    Private Sub CommandButton1_Click()
    Dim appWD As Object

    Set appWD = CreateObject("Word.Application")
    appWD.Visible = True
    appWD.Documents.Open Filename:="c:My Documentsdocname.doc"

    End Sub

    What I'd like to do now is to just launch the File|Open menu in Word so that I can choose any file or location. Can anyone help with this?

    Thanks in advance.

    Kyle

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    Hi Kyle,
    Try using:
    appWord.Dialogs(wdDialogFileOpen).Show
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Lounger
    Join Date
    Feb 2001
    Location
    Upstate, New York, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    Rory -

    Thanks for the help. When I try this, I get "Run time error 5941. The requested member of the collection does not exist". How do I fix this?

    Once again, I appreciate the help.

    Kyle

  4. #4
    Lounger
    Join Date
    Aug 2001
    Location
    Shropshire, UK
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    Because you use "appWD" and Rory has used "AppWord", a mispelling on Rory's part i think.
    Ewan.

  5. #5
    Lounger
    Join Date
    Feb 2001
    Location
    Upstate, New York, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    I should have mentioned this - I tried it both ways. Still got the same error. Any suggestions?

    Thanks.

    Kyle

  6. #6
    Star Lounger
    Join Date
    Nov 2001
    Location
    Illinois, USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    In Excel's VB Editor, choose Tools --> References, set a reference to Microsoft Word 9.0 Object Library.

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    Hi Kyle,
    Sorry about that - Dottie's right. You either need to set a reference to the Word object library ( in which case you could use Dim appWD as new word.application rather than using createobject) or change wdDialogFileOpen to 80:
    appWD.Dialogs(80).show
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Lounger
    Join Date
    Feb 2001
    Location
    Upstate, New York, USA
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Open Word doc from vba (Excel 2000/SR2)

    Rory & Dottie -

    Thanks so much for your help! It works perfectly.

    Kyle

Posting Permissions

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