Log in

View Full Version : [SOLVED:] Word Documents Close Only 1 Window - Leave Other Window Open



dj44
01-25-2017, 10:00 AM
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

macropod
01-25-2017, 06:05 PM
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).

dj44
01-25-2017, 06:23 PM
Hello Paul,

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

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

macropod
01-25-2017, 08:01 PM
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?

dj44
01-26-2017, 07:13 AM
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.

macropod
01-26-2017, 02:58 PM
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

dj44
01-26-2017, 03:37 PM
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 !