+ Reply to Thread
Results 1 to 8 of 8

Opening Existing Word file from Excel VBA

  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

    Please Login or Register  to view this content.
    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

    Please Login or Register  to view this content.
    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

    Please Login or Register  to view this content.

  7. #7
    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

    Already tried that. It comes up with a box stating:

    Please wait while Word finishes all pending print jobs.
    And when you click cancel print, it displays the doc and the margin warning is there.
    Here is my code for reference:

    Please Login or Register  to view this content.

  8. #8
    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 I found out an alternative!

    Just for anyone else who needs to know this!

    My situation:

    Wanting to have a button in excel for my users to print a letter template. (A standard thank you letter in this case)

    My problem:

    Margins

    My fix (Thanks to Excel Forum Members and myself)

    Excel Code:

    Sub OpenWord()
    Dim WordApp As Word.Application

    Set WordApp = Nothing
    Set WordApp = New Word.Application

    WordApp.Visible = False


    WordApp.Documents.Open "C:\HL1.docm"
    End Sub
    Word Code:

    Private Sub Document_Open()
    With Application
    .DisplayAlerts = wdAlertsNone
    .PrintOut Background:=False
    .Quit (wdDoNotSaveChanges)

    End With

    End Sub

+ 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