Consulting

Results 1 to 7 of 7

Thread: Word Documents Close Only 1 Window - Leave Other Window Open

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Word Documents Close Only 1 Window - Leave Other Window Open

    Hi folks, good wednesday

    hopefully a quick one i am trying to auto close a word document after 20 seconds.
    that I can do. However i have 2 word documents and its called a instance i belive ,

    so when i close the document it leaves behind the grey blank screen.

    For the life of me i cant work out what it wants. what will get it to close the ugly grey screen it leaves behind.

    While leaving my other word document as is I tried


     Sub CloseDoc()    
    
    'ActiveDocument.Close  
    
    'ThisDocument.ActiveWindow.Close 
       With Application           
     ThisDocument.ActiveWindow.Application.ActiveWindow.Close       
                '.ScreenUpdating = False         
      'Quit Word no save         
     '.Quit SaveChanges:=wdDoNotSaveChanges     
     End With End Sub
    thanks for any advice
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Leaving aside any coding errors, per se, if that macro is in the document you're trying to close, it will never quit Word because the macro stops running immediately you close the document. The result is that you're left with Word running but no document open (hence the grey pane).
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello Paul,

    Doh that makes sense, its been driving me up the wall, I thought it was a personal vendetta aginst me.

    So I need something in another document to say close that one, but I may not now the name of the other document.

    its a bit complicated opening various documents I cant keep track - I just want to close the second one after 30 seconds or so

    Any ideas what I could do otherwise im opening so may docs I cant keep track, and my window gets cluttered up anything for some peace
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You seem to be suggesting there are at least two documents open, but the code you've posted only refers to one. Why are you trying to close Word if you have more than one document open? How are you opening these documents? If either is opened by code, what code are you using for that and is that document the one you want to close?
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  5. #5
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello Paul,

    I was opening them from hyperlink in document,
    but too many I was opening so I thought I could close them on auto and just have my main one open.
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    In that case you might use code like:
    Sub CloseDocs()
    Dim i As Long, strNm As String
    strNm = ThisDocument.FullName
    For i = Documents.Count To 1 Step -1
      With Documents(i)
        If .FullName <> strNm Then .Close False
      End With
    Next
    ThisDocument.Activate
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  7. #7
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thanks Paul,

    I will put it in my active document and when I need those others to close run this and get my sanity back.

    Well the hyperlink has got a mind of its own - and I got to click on this document and that one - before you know it a lot of docs open.

    I could close them 1 by one as i was doing but sometimes i do open a group of docs - so this will help me

    Have a great evening !
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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