none
Opening a Word Document from an Excel VBA Module RRS feed

  • Question

  • As part of a complex Excel VBA module I want to open a Word Document (that contains a AutoOpen Macro)... I can open Word using "Application.ActivateMicrosoftApp xlMicrosoftWord", but I can work out how to open a specific document...
    Thursday, September 29, 2005 12:47 PM

Answers

  • per one of our support engineers:

    You need to set an object variable equal to the application, opening the application through createobject rather than activatemicrosoftapp. Set the application to visible if you need to see what’s going on, then you can use the object variable to access Word’s VBA to open the workbook:

     

    Sub automateword()

        Set wordapp = CreateObject("word.Application")

        wordapp.documents.Open "C:\Documents and Settings\anitao\My Documents\alo2004.doc"

        wordapp.Visible = True

    End Sub


     
    Article 307216 gives much more detail about using automation with Word

    How to use Automation with Word 2002

    http://support.microsoft.com/Default.aspx?kbid=307216

     
    I hope this is helpful,
    -brenda (ISV Buddy Team)

    Monday, October 10, 2005 7:52 PM

All replies

  • per one of our support engineers:

    You need to set an object variable equal to the application, opening the application through createobject rather than activatemicrosoftapp. Set the application to visible if you need to see what’s going on, then you can use the object variable to access Word’s VBA to open the workbook:

     

    Sub automateword()

        Set wordapp = CreateObject("word.Application")

        wordapp.documents.Open "C:\Documents and Settings\anitao\My Documents\alo2004.doc"

        wordapp.Visible = True

    End Sub


     
    Article 307216 gives much more detail about using automation with Word

    How to use Automation with Word 2002

    http://support.microsoft.com/Default.aspx?kbid=307216

     
    I hope this is helpful,
    -brenda (ISV Buddy Team)

    Monday, October 10, 2005 7:52 PM
  • Brenda,
    Thank you very much. A succinct answer, and PRECISELY what I needed.

    Your code was directly transferable and worked first time!

     

    Gnomie

    Tuesday, October 11, 2005 8:50 AM
  • I'm glad that it was helpful... I've forwarded your comment to the support engineer. Smile

    -brenda (ISV Buddy Team)
    Tuesday, October 11, 2005 6:05 PM
  • I am trying to do the exact same thing, however sometimes the code works, and sometimes it gives me an error - "Run-time error '13': Type mismatch". What can I input to make it work?

    Thursday, August 9, 2012 11:39 PM