+ Reply to Thread
Results 1 to 3 of 3

Open Word docm from Excel: Test if already open? Word errors?

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Open Word docm from Excel: Test if already open? Word errors?

    Coming along with generating Word documents from Excel, but running into a problem. The way I am creating the new document, there is no sign that a Word document is open. I guess that is good in this case, but I would like to know how to show the document if I do reconsider.

    When I go to open that document, if it is already open (and because of the way I am doing so, no one would know if it were already opened by a failure earlier, Heaven forbid!) my vba simply hangs. No warning, no notice, the run simply hangs. I would like to know:

    1) How to test if it is already open (And I don't know if I need to only test for if that document is open, or if Word is already open) so I could program around that, and also

    2) If it is already open, is there a means to "crash through" that, either destroying that already open instance and then proceeding or working through the warning.

    The most common I run into is a two-step process, where I first run into it already open so I have to stop everything, kill the process and move on, BUT, then I run into a sneaky remnant from that prior kill: Word once again hangs because it chooses to display a warning that the last time that document was opened it caused a serious problem... and once again I have to stop everything, kill the process, then I find I need to open the document, accept the warning that it caused a serious system problem and go ahead opening the document, then save the document back to where it originally was because Word chooses not to recognize the location any more, then I can run it all again. Royal Pain. Fine if all one is doing is addressing the document with Word, but not fine when trying to open it, modify it and save it programmatically!

    Help?

    The following was highly edited to get rid of a lot of ancillary material but preserve the basic construct as to how the document is being opened from Excel and manipulated:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Open Word docm from Excel: Test if already open? Word errors?

    Instead of creating a new instance of Word and then opening the document try grabbing the document with GetObject.

    If GetObject fails, and it will if the document isn't open, create a new instance of Word with CreateObject and then open the document.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: Open Word docm from Excel: Test if already open? Word errors?

    Is it best that I look up these items in the MS reference, or is there a better source to learn from?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Word browsing folder and open txt files in word document.
    By naseerrahaman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-16-2013, 03:38 AM
  2. Check if a Word File is Open and If Open Close it with Excel VBA.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2012, 11:14 AM
  3. Copy Excel Range into Word, without Normal.docm save prompt
    By Graham1 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-03-2011, 02:52 PM
  4. Macro to open word doc, then open another file in word and then excute a find replace
    By Uber-Smee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2010, 09:43 AM
  5. Replies: 2
    Last Post: 10-13-2006, 08:41 AM

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