Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2023, 05:59 PM
Guessed's Avatar
Guessed Guessed is offline Close inactive document Windows 10 Close inactive document Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
Close inactive document Close Document Without Saving Prompt 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

Other Forums: Access Forums

All times are GMT -7. The time now is 02:00 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft