• Open Word doc from vba (Excel 2000/SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Open Word doc from vba (Excel 2000/SR2)

    Author
    Topic
    #362799

    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

    Viewing 0 reply threads
    Author
    Replies
    • #551756

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

      • #551789

        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

        • #551835

          Because you use “appWD” and Rory has used “AppWord”, a mispelling on Rory’s part i think.
          Ewan.

          • #551868

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

            Thanks.

            Kyle

            • #551907

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

        • #551936

          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.

          • #551960

            Rory & Dottie –

            Thanks so much for your help! It works perfectly.

            Kyle

    Viewing 0 reply threads
    Reply To: Open Word doc from vba (Excel 2000/SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: