Results 1 to 3 of 3
  1. #1
    DMT Dave is offline VIP
    Windows 10 Access 2016
    Join Date
    May 2018
    Posts
    1,371

    Check If Word Open


    Hi Guy's, I am trying to find a short piece of code to close a word document but checking that it is still open as the wdDoc is set to visible false

    I am getting a debug on the bold line

    Code:
       Dim wdApp As Word.Application
        Set wdApp = GetObject(, "Word.Application")
        If wdApp.ActiveDocument = "" Then
        DoCmd.CancelEvent
        Else
        wdApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
       End If
       

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    check with
    wdApp.documents.count

    if 0, then no docs are open.

    To shutdown all of Word and all documents, just use
    wdApp.Quit False

  3. #3
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    aside from the solution, which is fine if there's no chance of 2 or more documents being open, think about what wdApp.ActiveDocument is - an object.
    It can't be compared to an empty string.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Open Embedded Word Doc
    By ck4794 in forum Programming
    Replies: 2
    Last Post: 10-29-2013, 01:24 PM
  2. merging check box information into Word Docs
    By LeesKeys in forum Access
    Replies: 1
    Last Post: 10-19-2011, 03:37 PM
  3. How to open a word/excel/other file in vba
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-28-2010, 10:36 PM
  4. Open Word Doc in foreground
    By patrickmcdiver in forum Programming
    Replies: 1
    Last Post: 03-02-2010, 12:26 AM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums