![]() |
|
#1
|
||||
|
||||
![]()
If you are explicit about what document you want to close then you need to handle an error if that document isn't open. You might also want to ensure it isn't the foreground doc. This code looks through the current docs to close a specific one only if it is not the active document.
Code:
Sub CloseADoc() Dim aDoc As Document For Each aDoc In Application.Documents Debug.Print aDoc.Name If aDoc.Name = "Document2" And ActiveWindow.Document.Name <> "Document2" Then aDoc.Close SaveChanges:=False Exit For End If Next aDoc End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to dectect if close document and now no document open | skarden | Word VBA | 2 | 10-24-2022 07:03 AM |
![]() |
Joe528 | Word | 3 | 10-08-2021 06:12 PM |
Document close if/then/else error | eduzs | Word VBA | 1 | 01-02-2021 05:56 AM |
Save and Close powerpoint if it is inactive | MetteGaga | PowerPoint | 0 | 04-16-2015 05:14 AM |
Prompt when close the document | ubns | Word | 15 | 04-29-2012 10:07 PM |