+ Reply to Thread
Results 1 to 8 of 8

Opening Existing Word file from Excel VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2009
    Location
    Nashville, TN,USA
    MS-Off Ver
    Excel 2007
    Posts
    87

    Opening Existing Word file from Excel VBA

    Hello All!

    I have read the many threads across the internet on this and copied and pasted so much code that my fingers hurt!

    The only error that I am getting from any code that I try is

    Run-time Error '5174'

    This file could not be found
    (c:\test.doc)

    The file that it is looking for is there, and is not hidden or a read only.

    Anyone have any ideas?
    Last edited by rbyrd023; 12-10-2010 at 02:10 PM.

  2. #2
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Opening Existing Word file from Excel VBA

    Try

    Sub Test()
    Dim WordApp As Word.Application
    
    Set WordApp = Nothing
    Set WordApp = New Word.Application
    WordApp.Visible = True
    WordApp.Documents.Open "C:\New Word 2007 Document.docx"
    
    End Sub
    having made a reference to the Word object model.

  3. #3
    Registered User
    Join Date
    04-04-2009
    Location
    Nashville, TN,USA
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Opening Existing Word file from Excel VBA

    That worked great.

    THANK YOU

    I have added the printout method to the file that I am opening, and after the printout method, I want Word to close. I've tried a few lines but all it does is close the document. ANy way to close Word entirely?

  4. #4
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Opening Existing Word file from Excel VBA

    Try

    WordApp.Quit
    Set WordApp = Nothing
    at the end.

  5. #5
    Registered User
    Join Date
    04-04-2009
    Location
    Nashville, TN,USA
    MS-Off Ver
    Excel 2007
    Posts
    87

    Re: Opening Existing Word file from Excel VBA

    Ok that Worked!!!!

    One last thing! (Sorry)

    The doc that I have is set up so that a warning on the print margins comes up when I print it. It prints just fine, but I want it to no give that warning. Any code for that?

  6. #6
    Forum Expert mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2013
    Posts
    4,967

    Re: Opening Existing Word file from Excel VBA

    You could try

    WordApp.DisplayAlerts = wdAlertsNone

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1